Newton method is used for finding root of the function in given interval.

## Algorithm:

```IN:
Function f, which is continous function and value: a - being intital guess - the closer to root, the better. Function fD, which is the derivative of function f.
OUT:
Root in given interval.
1. Make x = a and prevX = a.
2. Check if abs(f(x)) < precision.
3. If it is end algorithm and return x.
4. Make x = prevX - (f(prevX) / fD(prevX)).
5. Make prevX = x.
6. Go to step 2.```

## Sample Output:

```f(x) = x * (x + 2) -1
-3

root: -2.414201183431953```
Iteration NumberaprevXxf(x)
1-3-3-32.0
2-3-32.50.25
3-32.5-2.4160.0069
4-3-2.416-2.4146.007E-6

## Pros:

• easy to implement (without approximating the derivative of function!).
• very fast method (not counting some special functions).
• no need to find initial interval, simply choose a number and one of the roots should be found.

## Cons:

• has trouble with some functions.
• If a stationary point of given function is encountered, there will be division by zero, because of the derivative being zero.
• need to calculate derivative of given function.
• may miss root.

Newton Method Algoritm
Tagged on: