Pre-Engineering 220 Introduction to MatLab ® & Scientific Programming j kiefer



Download 8.69 Mb.
Page22/128
Date02.05.2018
Size8.69 Mb.
#47255
1   ...   18   19   20   21   22   23   24   25   ...   128

In effect we have approximated f(x) by a straight line; x is the intercept of that line with the x-axis. It may or may not be a good approximation for the root .


% Script to implement Newton's Method

del=1


x=3

k=0


func=inline('x^3-587')

deriv=inline('3*x^2')


while del >= 0.00005

k=k+1


if k <= 10

xnew=x-func(x)/deriv(x);

del=abs((xnew-x)/x);

disp(x);disp(func(x));disp(del)

x=xnew;

end


end

b. Algorithm



i) choose an initial estimate, xi

ii) compute f(xi) and

iii) compute the new estimate:

iv) return to step (ii) with i = i + 1


c. Comments

It turns out that if the initial estimate of the root is a good one, then the method is guaranteed to converge, and rapidly. Even if the estimate is not so good, the method will converge to a root—maybe not the one we anticipated.


Also, if there is a point nearby the method can have trouble. It’s always a good thing to graph f(x) first.



Download 8.69 Mb.

Share with your friends:
1   ...   18   19   20   21   22   23   24   25   ...   128




The database is protected by copyright ©ininet.org 2024
send message

    Main page