{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture 4 - Lecture 4 If statements While loops BMEn 2401...

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

View Full Document Right Arrow Icon
9/28/2010 1 Lecture 4: If statements, While loops BMEn2401 Programming for Biomedical Engineers Rich Beck September 28, 2010 1 Today’s Lecture Relational and logical operators if-end statements while-end loops 2
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
9/28/2010 2 Review So far we have learned Scalar variables and operators: Radius = 2.8; Sphere_Volume = 4/3*pi*Radius^3 Arrays and array operators: V3 = V1.^2 ./ ( 3*V2 + V2.*V1) X = A^-1 * b Some MATLAB built-in functions sqrt(x), sum (v), … Use Help -> Product Help to Search… ex. rem 3 Test Yourself (Review) Write a script that queries the user to input the height, length, and width of a cube from the command window and calculate the volume of the cube 4
Image of page 2
9/28/2010 3 Logical Statements and Relational Operators Statement = a > b It is 1 if a is greater than b (true) It is 0 if a is not greater than b (false) Example: Statement1 = 5 > -3 ; Statement2 = sqrt ( 16 ) > 8 ; Statement1 = 1 Statement2 = 0 5 Relational Operators < Less than > Greater than <= Less than or equal to >= Greater than or equal to == Equal to ~= Not equal to Relational operators are always performed element-by-element in arrays. Note that the “equal to” operator consists of two “=“ signs. 6
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
9/28/2010 4 Test Yourself What are the values of statement1 , statement2 , and statement3 ? statement1 = ( 1 / 4 ) < ( 1 / 5 ) x2 = 9; statement2 = (-x2)^2 ~= x2^2 A=[ 0 2; 3 4]; B=[ 0 1; 6 9]; statement3 = A <= B 7 Logical Operators Logical operators are used to combine logical statements (s1, s2). Operator Name Description & AND ( s1 & s2 ) is true (i.e. 1) only when both s1 and s2 are true. | OR ( s1 | s2 ) is true (i.e. 1) when either one of s1 or s2 or both of them are true.
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