HW1 Sol

HW1 Sol - EE 103, Winter 09, Prof SEJ: HW 1 Sol. Applied...

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

View Full Document Right Arrow Icon
EE 103, Winter ’09, Prof SEJ: HW 1 Sol. Page 1 of 12 Applied Numerical Computing Instructor: Prof. S. E. Jacobsen HW1 Solution Students: Distributed HW solutions are a component of the course and should be fully understood. SEJ Problem 1) To find the roots of the equation 0 1 1 . 62 2 = + x x , using four-digit arithmetic we compute: b 2 4 ac = fl (( 62.1) 2 ) 4 = fl (3856.41) 4 = 3856 4 = 3852 = fl (62.0645) = 62.06 therefore if we use four-digit arithmetic and the quadratic formula, the two roots will be: fl ( r 1 ) = b + b 2 4 ac 2 a = (62.1 + 62.06) 2 = 62.08 fl ( r 2 ) = b b 2 4 ac 2 a = (62.1 62.06) 2 = 0.02 But the roots of the equation, 0 1 1 . 62 2 = + x x (to seven decimal places) are 0838928 . 62 1 = r and 0161072 . 0 2 = r . If we round these numbers to four digits, we will have 08 . 62 1 = r and 01611 . 0 2 = r . What we found instead are fl ( r 1 ) = 62.08 and fl ( r 2 ) = 0.02 . So the relative errors are | | | ) ( | 1 1 1 r r r f = 0.0 and | | | ) ( | 2 2 2 r r r f = 24 . 0 01611 . 0 00389 . 0 The percentage error for the second root is approximately 24%. This error is very large and clearly unacceptable. The reason for this large error is subtractive cancellation, which occurs when two close numbers are subtracted (in this case b=62.1 and 06 . 62 4 2 ac b ). while at least one of them is subject to error (here we have error due
Background image of page 1

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

View Full DocumentRight Arrow Icon
EE 103, Winter ’09, Prof SEJ: HW 1 Sol. Page 2 of 12 to rounding to 4 digits). Alternatively we may write: ac b b c ac b b ac b b a ac b b 4 2 4 4 2 4 2 2 2 2 + = + + 0161 . 0 06 . 62 1 . 62 2 = + = Here our relative error is | f ( r 2 ) r 2 | | r 2 | = 1.0879 × 10 4 which is much smaller than the previous value of relative error. We do not rewrite the formula for the other root since subtractive cancellation does not occur in its computation and therefore its relative error is small. Problem 2) The following m-file, called Bisection.m contains the script for a bisection algorithm. Of course you will need to provide the name of the m-file corresponding to the function you would like to use. Problems 3 and 4 demonstrate how this script is used with different functions. % % Bisection.m is a script that runs the bisection algorithm on any function. % fun=input('What function do you wish to call? ','s') a(1)=input('What is the value of a ? '); b(1)=input('What is the value of b ? '); if a >= b disp('a must be less than b'); return; end e=input('What is the value of the interval tolerance parameter? '); itmax=input('What is the max number of iterations allowed? ');
Background image of page 2
EE 103, Winter ’09, Prof SEJ: HW 1 Sol.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 12

HW1 Sol - EE 103, Winter 09, Prof SEJ: HW 1 Sol. Applied...

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

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