{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture 4

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

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

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

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

View Full Document
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
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

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

View Full Document
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.
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