# lecture4a - CEE/MAE M20 Matlab elements covered last week...

• Test Prep
• 34
• 100% (1) 1 out of 1 people found this document helpful

This preview shows pages 1–5. Sign up to view the full content.

CEE/MAE M20 Matlab elements covered last week Loop and recursions 1 CEE/MAE M20 Matlab elements covered last week Loop and recursions 1 for values of loop index repeat these statements end CEE/MAE M20 Matlab elements covered last week Loop and recursions 1 for values of loop index repeat these statements end while termination criterion not met repeat these statements end CEE/MAE M20 Matlab elements covered last week Loop and recursions 1 for values of loop index repeat these statements end while termination criterion not met repeat these statements end Use for loop if we know in advance how many times to repeat CEE/MAE M20 Matlab elements covered last week Loop and recursions 2 for values of loop index repeat these statements end for j = 268:-8:-35 fprintf(‘This is iteration %d\n’,j); end CEE/MAE M20 Matlab elements covered last week Loop and recursions 2 for values of loop index repeat these statements end for j = 268:-8:-35 fprintf(‘This is iteration %d\n’,j); end Decrease from 268 in steps of -8 to smallest number >= -35

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

CEE/MAE M20 Matlab elements covered last week Loop and recursions 3 while termination criterion not met repeat these statements end CEE/MAE M20 Matlab elements covered last week Loop and recursions 3 while termination criterion not met repeat these statements end while Boolean Expression Code Fragment o The Loop Body end Keywords The syntax of while- loop statement in MATLAB. CEE/MAE M20 Matlab elements covered last week Loop and recursions 3 while termination criterion not met repeat these statements end while Boolean Expression Code Fragment o The Loop Body end Keywords The syntax of while- loop statement in MATLAB. hour = input( 'Enter hour: ' ); while (hour < 0 || hour > 23) fprintf( 'ERROR: Invalid hour. Please try again.\n' ); hour = input( 'Enter hour: ' ); end Introduction to Computer Programming with MATLAB CEE/MAE M20 Lecture 4a 1-D Arrays and the Discrete vs. the Continuous CEE/MAE M20 Week 4 Reading: ITC Chapter 4 5 CEE/MAE M20 1-D arrays 6
CEE/MAE M20 Example: Plotting sine Suppose we wish to plot sin(x) for 0 <= x <= 2 π . We now what it should look like: 7 x 0 1 2 3 4 5 6 sin(x) -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 CEE/MAE M20 Example: Plotting sine Suppose we wish to plot sin(x) for 0 <= x <= 2 π . We now what it should look like: 7 x 0 1 2 3 4 5 6 sin(x) -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 How do we do this? CEE/MAE M20 Table Plot 8 x sin(x) 0.00 0.0 1.57 1.0 3.14 0.0 4.71 -1.0 6.28 0.0 Insight Through Computing CEE/MAE M20 Table Plot 8 x sin(x) 0.00 0.0 1.57 1.0 3.14 0.0 4.71 -1.0 6.28 0.0 Insight Through Computing Plot based on 5 points CEE/MAE M20 Table Plot 8 x sin(x) 0.00 0.0 1.57 1.0 3.14 0.0 4.71 -1.0 6.28 0.0 Insight Through Computing Plot based on 5 points Not enough points to discern the underlying function. CEE/MAE M20 Table Plot 9 x sin(x) 0.000 0.000 0.784 0.707 1.571 1.000 2.357 0.707 3.142 0.000 3.927 -0.707 4.712 -1.000 5.498 -0.707 6.283 0.000 Insight Through Computing

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

CEE/MAE M20 Table Plot 9 x sin(x) 0.000 0.000 0.784 0.707 1.571 1.000 2.357 0.707 3.142 0.000 3.927 -0.707 4.712 -1.000 5.498 -0.707 6.283 0.000 Plot based on 9 points Insight Through Computing CEE/MAE M20 Table Plot 9 x sin(x) 0.000 0.000 0.784 0.707 1.571 1.000 2.357 0.707 3.142 0.000 3.927 -0.707 4.712 -1.000 5.498 -0.707 6.283 0.000 Plot based on 9 points Insight Through Computing Getting better, but still not a good representation.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern