lecture3a - CEE/MAE M20 Matlab elements covered previously...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CEE/MAE M20 Matlab elements covered previously Logical expressions and conditionals 1 Logical data types >> a = true a = 1 Relational operators if (expression is true) do something else do something else end == Equal to ~= Not equal to > Greater than >= Greater than or equal to < Less than <= Less than or equal to Logic (Boolean) operators In MATLAB Operation && Logical AND || Logical inclusive OR xor Logical exclusive OR ~ Logical NOT switch (switch_expression) case case_expr_1 stuff to do case case_expr_2 stuff to do case case_expr_3 stuff to do . . otherwise stuff to do end Introduction to Computer Programming with MATLAB CEE/MAE M20 Lecture 3a Iteration, recursion, and error CEE/MAE M20 ITC Reading 3 CEE/MAE M20 Loops and Recursion 4 CEE/MAE M20 Loops and Recursion Computer programs often require repeating a task several times 4 CEE/MAE M20 Loops and Recursion Computer programs often require repeating a task several times Need some way of allowing loops and recursion . 4
Image of page 1

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

View Full Document Right Arrow Icon
CEE/MAE M20 Loops and Recursion Computer programs often require repeating a task several times Need some way of allowing loops and recursion . In programming, these are provided by for and while loops 4 CEE/MAE M20 Continuous to discrete 5 CEE/MAE M20 Continuous to discrete In calculus, we deal with derivatives and integrals 5 CEE/MAE M20 Continuous to discrete In calculus, we deal with derivatives and integrals These are continuous operations, requiring infinitely small distances or time steps 5 CEE/MAE M20 Continuous to discrete In calculus, we deal with derivatives and integrals These are continuous operations, requiring infinitely small distances or time steps A computer only allows small (but finite) differences 5 CEE/MAE M20 Continuous to discrete In calculus, we deal with derivatives and integrals These are continuous operations, requiring infinitely small distances or time steps A computer only allows small (but finite) differences So we must rely on discrete approximations Derivatives become divided differences Integrals become summations 5
Image of page 2
CEE/MAE M20 Continuous to discrete In calculus, we deal with derivatives and integrals These are continuous operations, requiring infinitely small distances or time steps A computer only allows small (but finite) differences So we must rely on discrete approximations Derivatives become divided differences Integrals become summations Loops and recursion are our most valuable tools 5 CEE/MAE M20 6 The basic constructs CEE/MAE M20 6 for values of loop index repeat these statements end The basic constructs CEE/MAE M20 6 for values of loop index repeat these statements end while termination criterion not met repeat these statements end The basic constructs CEE/MAE M20 6 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 The basic constructs CEE/MAE M20 7 Example 1 for j = 1:1:100 fprintf(‘This is iteration %d\n’,j); end
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
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