Newton Rhapson - this one

April 14 2008 by bongiman 128
false

0


I decided to repost this as the previous one went crazy.......

I'm trying to construct an iterative procedure NR1(f,x0,N) where f is a function, x0 is an initial estimate (which can be complex) and N the number of iterates.

Given:  xk+1=xk - f(xk)/f'(xk), k=0,1,2....,

Now for example by defining f:= x-> x^2-2 and inputting x0=1 and N=10 i should be able to check that my procedure calculates sqrt(2) correctly.

This is what i've got so far.....

NR1:= proc(f,x0,N)
> local x,k,f:
> x := x0:
> for k to N do:
>   x := x-f/D(f)
> end do:
>  evalf(x):
> end proc:f:= x-> x^2-2:
> NR1(f,1,10);
 

Could someone point out where i'm going wrong?

Thanks.

 
Loading Comments & Answers

You must be logged into your MaplePrimes account in order to post a comment. If you don't have an account, you can create an account here.

     

Forgot Your Password? Create an Account