03.05.2014 Views

Introduction to Numerical Math and Matlab ... - Ohio University

Introduction to Numerical Math and Matlab ... - Ohio University

Introduction to Numerical Math and Matlab ... - Ohio University

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

10 LAB 3. NEWTON’S METHOD AND FOR LOOPS<br />

For f(x) = x 1/3 we have x ∗ = 0 but f ′ (x ∗ ) = ∞. If you try<br />

> f = inline(’x^(1/3)’)<br />

> f1 = inline(’(1/3)*x^(-2/3)’)<br />

> x = mynew<strong>to</strong>n(f,f1,0.1,10)<br />

then x explodes.<br />

For f(x) = x 2 we have x ∗ = 0 but f ′ (x ∗ ) = 0. If you try<br />

> f = inline(’x^2’)<br />

> f1 = inline(’2*x’)<br />

> x = mynew<strong>to</strong>n(f,f1,1,10)<br />

then x does converge <strong>to</strong> 0, but not that rapidly.<br />

If x 0 is not close enough <strong>to</strong> x ∗ that the linear approximation (3.2) is valid, then the iteration (3.4)<br />

gives some x 1 that may or may not be any better than x 0 . If we keep iterating, then either<br />

• x n will eventually get close <strong>to</strong> x ∗ <strong>and</strong> the method will then converge (rapidly), or<br />

• the iterations will not approach x ∗ .<br />

Exercises<br />

3.1 Use mynew<strong>to</strong>n on the function f(x) = x 5 − 7, with x 0 = 2. By trial <strong>and</strong> error, what is the<br />

lowest value of n for which the program converges (s<strong>to</strong>ps changing). How close is the answer<br />

<strong>to</strong> the true value? Plug the program’s answer in<strong>to</strong> f(x); is the value zero?<br />

3.2 Suppose a ball with a coefficient of elasticity of .9 is dropped from a height of 2 meters on<strong>to</strong><br />

a hard surface. Write a script program <strong>to</strong> calculate the distance traveled by the ball after n<br />

bounces. Include lots of comments. By trial <strong>and</strong> error approximate how large n must be so<br />

that <strong>to</strong>tal distance s<strong>to</strong>ps changing. Turn in the program <strong>and</strong> a brief summary of the results.<br />

3.3 For f(x) = x 3 − 4, perform 3 iterations of New<strong>to</strong>n’s method with starting point x 0 = 2. (On<br />

paper, but use a calcula<strong>to</strong>r.) Calculate the true solution (x ∗ = 4 1/3 ) in <strong>Matlab</strong> <strong>and</strong> find the<br />

errors <strong>and</strong> percentage errors of x 0 , x 1 , x 2 <strong>and</strong> x 3 . Put the results in a table.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!