# Thread: Newton Raphson method code

1. ## Newton Raphson method code

I need to use the Newton Raphson method in a program to find the roots of a polynomial. The polynomial is z^5 - z - 1. I'm not too sure how to deal with the complex roots. Does anyone know where I can find code that implements it. Thanks

2. I did a google search, and the first result was exactly what you are looking for.

3. Well you have at least two approaches to this problem:

1. Newton Raphson formulae is:
z(k+1)=z(k)-f(z(k))/f'(z(k));
In your case z is a complex number so question of multipling and dividing of complex number arises.
You can declare strut complex and define functions which will handle this.
I'm sure you can find a lot of examples of class complex here on this board.

2. You know this: z=x+jy where X,y are Real numbers. So you can write soething like this:
(x+jy)^5-(x+jy)-1=0; Now you apply the binomial formulae (not sure you call it that way). After that use this:
Real(equation)=0
Imag(equation)=0
And basically you'll get a system of two equations with two unknown variables x,y. Now you can apply Newton Raphson method for systems. You'll get matrix... need to calculate inverese Jacobi matrix which is probably harder approach.

Any please try not to post homework. We're simply not going to do it for you.
Post your code where you having problems. That's OK