L4post - Previous Lecture: Branching (if, elseif, else,...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
± Previous Lecture: ± Branching ( if , elseif , else , end ) ± Relational operators ( < , >= , == , ~= , …, etc.) ± Today’s Lecture: ± Logical operators ± More branching— nesting ± Announcements: ± Project 1 (P1) due Thursday at 11pm ± Submit real .m files (plain text, not from a word processing software such as Microsoft Word) ± Discussion sections this week in the lab, UP B7 ± Register your clicker with CIT. Use the link on course website.
Background image of page 1

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

View Full DocumentRight Arrow Icon
September 8, 2009 Lecture 4 2 Consider the quadratic function q ( x ) = x 2 + bx + c on the interval [ L , R ] : ± Is the function strictly increasing in [ L , R ] ? ± Which is smaller , q ( L ) or q ( R ) ? ± What is the minimum value of q ( x ) in [ L , R ] ?
Background image of page 2
September 8, 2009 Lecture 4 3 % Which is smaller, q(L) or q(R)? qL= L*L + b*L + c; % q(L) qR= R*R + b*R + c; % q(R) if ( qL == qR ) disp(‘qleft and qright are equal’) elseif ( qL < qR ) disp(‘qleft is smaller’) else disp(‘qright is smaller’) end
Background image of page 3

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

View Full DocumentRight Arrow Icon
September 8, 2009 Lecture 4 4 The if construct if boolean expression1 statements to execute if expression1 is true elseif boolean expression2 statements to execute if expression1 is false but expression2 is true : else statements to execute if all previous conditions are false end C a n h v e y u m b r of l s i f c
Background image of page 4
September 8, 2009 Lecture 4 5 Consider the quadratic function q ( x ) = x 2 + bx + c on the interval [ L , R ] : What if you only want to know if q ( L ) is close to q ( R ) ?
Background image of page 5

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

View Full DocumentRight Arrow Icon
September 8, 2009 Lecture 4 6 % Is q(L) close to q(R)? tol= 1e-4; % tolerance qL= L*L + b*L + c; qR= R*R + b*R + c; if ( abs(qL-qR) < tol ) disp(‘qleft and qright similar’) end N a m e n i p o r t d de f w it h c !
Background image of page 6
September 8, 2009 Lecture 4 8 Can have if without else if boolean expression statements to execute if expression is true end
Background image of page 7

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

View Full DocumentRight Arrow Icon
September 8, 2009 Lecture 4 9 Do these two fragments do the same thing? % given x, y if x>y disp(‘alpha’) else disp(‘beta’) end % given x, y if x>y disp(‘alpha’) end if y>=x disp(‘beta’) end A: yes B: no
Background image of page 8
September 8, 2009 Lecture 4 10 The if construct if boolean expression1 statements to execute if expression1 is true elseif boolean expression2 statements to execute if expression1 is false but expression2 is true : else statements to execute if all previous conditions are false end C a n h v e y u m b r of l s i f c t os on ls
Background image of page 9

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

View Full DocumentRight Arrow Icon
September 8, 2009 Lecture 4 12 Things to know about the if construct ± At most one branch of statements is executed ± There can be any number of elseif clauses ± There can be at most one else clause ± The clause
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/06/2010 for the course CS 9339 taught by Professor Gries during the Fall '09 term at Cornell University (Engineering School).

Page1 / 48

L4post - Previous Lecture: Branching (if, elseif, else,...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online