Lecture 2 Notes

Lecture 2 Notes

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ement: xc <= L Insight Through Computing L R Insight Through Computing Critical Points L R So what is the requirement? 2 What are critical points? •  boundary points •  points where derivative is zero, {x | q’(x) = 0} So, •  x=L, x =R, x = - b/2 q( x) = x + bx + c xc = −b / 2 % Determine whether q increases % across [L,R] xc = -b/2; if L R fprintf(‘Yes\n’) else fprintf(‘No\n’) end q ( x ) = x 2 + bx + c q '( x ) = 2 x + b q '( xc ) = 0 => xc = −b / 2 Relational Operators < Less than > Greater than <= Less than or equal to >= Greater than or equal to == Equal to ~= Not equal to Lecture 3 16 Insight Through Computing Solution Fragment So what is the requirement? % Determine whether q increases % across [L,R] xc = -b/2; if xc <= L fprintf(‘Yes\n’) else fprintf(‘No\n’) end Lecture 3 xc = -b/2; if xc <= L disp(‘Yes’) else disp(‘No’) end Relational Operators < Less than > Greater than <= Less than or equal to >= Greater than or equal to == Equal to ~= Not equal to 16 Insight Through Computing 11 1/28/14 So what is the requirement? Problem 2 % Determine whether q increases % across [L,R] xc = -b/2; disp(‘Yes’) if fprintf(‘Yes\n’) else disp(‘No’) end Lecture 3 Write a fragment that prints the maximum value that q(x) attains on the interval. 20 Insight Through Computing Maximum at L Maximum at R xc = −b / 2 q( x) = x 2 + bx + c xc = −b / 2 q( x) = x 2 + bx + c Depends on whether xc is to the right or left of the interval midpoint. Insight Through Computing L R Looks obvious, but how can we prove this? Show 1.  q is symmetric about xc, i.e. for any s, q(xc- s)=q(sc+s) 1.  q is increasing from xc, i.e. for s>0, t>s, q(xc+s) < q(xc+t) Insight Through Computing Insight Through Computing L R Solution Fragment xc = -b/2; Mid = (L+R)/2; if xc <= Mid maxVal = R^2 + b*R + c else maxVal = L^2 + b*L + c end Insight Through Computing 12 1/28/14 No! Problem 3 xc = −b / 2 q( x) = x 2 + bx + c Write a fragment that prints “yes” if xc is in the interval and “no” if xc is not in the interval. Because xc < L Insight Through Computing Insight Through Computing L No! Yes! xc = −b / 2 q( x) = x 2 + bx + c Because R < xc Insight Through Computing xc = −b / 2 q( x) = x 2 + bx + c Because L <= xc and xc <= R L R Insight Through Computing Solution Fragment xc = -b/2; if (L <= xc) && (xc <= R) disp(‘Yes’) else disp(‘No’) end Illegal: Insight Through Computing R L R Saying the Opposite xc is in the interval [L,R] if L <= xc and xc <= R xc is not in the interval [L,R] if xc < L or R < xc L <= xc <= R Insight Through Computing 13 1/28/14 Another Solution Fragment xc = -b/2; if (xc < L) || (R < xc) disp(‘No’) else dis...
View Full Document

This document was uploaded on 03/11/2014 for the course CSCI 004 at Brown.

Ask a homework question - tutors are online