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

Info icon 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
Image of page 1

Info icon 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
Image of page 2
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
Image of page 3

Info icon 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.
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern