Lecture 08 Presentation

Lecture 08 Presentation - 14:440:127 Introduction to...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 14:440:127 Introduction to Computers for Engineers Lecture 8 LEASE TAKE LECTURE 8 NOTES PLEASE TAKE LECTURE 8 NOTES AS YOU ENTER THE ROOM! Lecturer: Blase E. Ur Recitation Instructor: Bo Jin Recitation Instructor: Cyrus Gerami Recitation Instructor: Vishnu Vijayakumar Recitation Instructor: Wen Yueh 14:440:127 Lecture 8 Efficiency 1) Loops are bad 2) Pre-allocating memory is good Rutgers University School of Engineering 14:440:127 Lecture 8 Efficiency 1) Loops are bad 1) tic (starts a timer) 2) toc (stops a timer) Rutgers University School of Engineering 14:440:127 Lecture 8 Efficiency- Pre-allocate memory tic for z = 1:10000 x(z) = 5; end toc % this took 0.18 seconds Rutgers University School of Engineering tic V = zeros(1,10000); % preallocating! for j = 1:10000 V(j) = 5; end toc % this took 0.0001 seconds 14:440:127 Lecture 8 Efficiency 1) Better: use built-in functions % Use built-in functions tic x = 5*ones(1,10000); Rutgers University School of Engineering x = 5*ones(1,10000); toc % 0.000059 seconds 14:440:127 Lecture 8 Animation 1) Make a loop 2) Each time you go through the loop, change something 3) Pause each time you go through the loop 4) Have a constant axis Rutgers University School of Engineering 14:440:127 Lecture 8 Animation % X floating through space for t=0:0.1:20 % choose a small interval x=t*cos(t); y=5*sin(t); pause(0.05) % can come anywhere in the loop Rutgers University School of Engineering pause(0.05) % can come anywhere in the loop plot(x,y,'X') axis([-20 20 -5 5]) % must follow plot end 14:440:127 Lecture 8 Animation % X floating through space, precomputed t = 0:0.1:20; x=t.*cos(t); % don't forget dot operations y=5*sin(t); for j = 1:length(x) Rutgers University School of Engineering for j = 1:length(x) pause(0.05) % can come anywhere in the loop plot(x(j),y(j),'X') axis([min(x) max(x) min(y) max(y)]) end 14:440:127 Lecture 8 Animation % X floating through space, leaving a trail t = 0:0.1:20; x=t.*cos(t); % don't forget dot operationsx=t....
View Full Document

Page1 / 33

Lecture 08 Presentation - 14:440:127 Introduction to...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online