Newton's Method Calculator

f(x) =
Initial guess (x0):
Convergence criteria (ε, δ):
(desired accuracy/precision)
Solution:

Newton's Method Lesson

Lesson Contents

What is Newton's Method?

In numerical analysis, we use an algorithm or equation to repeat calculations towards a solution until the desired level of accuracy and precision is reached. These repeated calculations are called iterations.

Newton’s Method, also known as the Newton-Raphson method, is a numerical algorithm that finds a better approximation of a function’s root with each iteration.

How to Calculate the Roots of a Function Using Newton's Method

The general equation for Newton’s Method is given as:

$$x_{i + 1} = x_{i} \; – \; \frac{f(x_{i})}{f'(x_{i})}; \; i=0, 1, 2…$$

Where xi + 1 is the x value being calculated for the new iteration, xi is the x value of the previous iteration, f(xi) is the function’s value at xi, and f ‘(xi) is the value of the function’s derivative at xi.

For the first iteration i = 0 we will plug 0 in for in the general equation. This results in:

$$x_{(0) + 1} = x_{(0)} \; – \; \frac{f(x_{(0)})}{f'(x_{(0)})} \; \Rightarrow \; x_{1} = x_{0} \; – \; \frac{f(x_{0})}{f'(x_{0})}$$

To begin the calculation process, we must decide on an initial guess of the root which we will call x0. The initial guess can be any real number but keep in mind that the closer our initial guess is to the actual root of the function, the more likely we are to find a solution quickly.

Then, evaluate the function and its derivative at x = x0. Plug x0, f(x0), and f ‘(x0) into the equation to find x1. We have now completed the first iteration and must determine if more iterations are necessary.

To determine if more iterations are necessary, we use the following convergence criteria formulas:

$$\lvert x_{i + 1}  \; –  \; x_{i} \rvert \leq \varepsilon \; \text{ and } \; \lvert f(x_{i + 1}) \rvert \leq \delta $$

Where xi + 1 is the x value being calculated for the new iteration, xi is the x value of the previous iteration, ε is the desired precision (closeness of successive x values), f(xi+1) is the function’s value at xi+1, and δ is the desired accuracy (closeness of approximated root to the true root).

We must decide on the value of ε and δ and leave them constant during the entire run of iterations. The smaller these values are, the more precise and accurate our solution will be. However, if we set the values too small, it could take an excessive amount of iterations to satisfy the convergence criteria.

Now, we check if the convergence criteria have been satisfied by plugging the values of the respective variables into each of the two convergence criteria formulas. For the first iteration i = 0, this will look like:

$$ \begin{align} & \lvert x_{(0)+1} \; – \; x_{(0)} \rvert \leq \varepsilon \; \Rightarrow \; \lvert x_{1} \; – \; x_{0}\rvert \leq \varepsilon \\ \\ & \lvert f(x_{(0) \; + \; 1}) \rvert \leq \delta \; \Rightarrow \; \lvert f(x_{1}) \rvert \leq \delta \end{align}$$

For the convergence criteria to be satisfied, the inequalities in each of the formulas must be true. If one of the inequalities is true but the other is not, convergence has not been met and iteration must continue until the convergence criteria have been satisfied.

If the convergence criteria have been satisfied on a given iteration, calculations are stopped and the x value for that iteration is taken as the solution.

Sometimes Newton’s Method will diverge away from a solution and the convergence criteria will never be satisfied. This may happen in any number of iterations. If using a computer to solve with Newton’s Method, it is important to set a maximum number of iterations such that calculations will be stopped before a potentially infinite number of iterations occur.

Example Problem

Calculate the root of f(x) = x2 – 10 using Newton’s Method.

1.) Using the general equation for Newton’s Method:

$$x_{i + 1} = x_{i} \; – \; \frac{f(x_{i})}{f'(x_{i})}$$

Convergence when:

$$\lvert x_{i + 1} \; – \; x_{i} \rvert \leq \varepsilon \: \text{ and } \: \lvert f(x_{i + 1}) \rvert \leq \delta$$

Using ε = 0.0001 and δ = 0.0001

2.) Given f(x) = x2 – 10, find f ‘(x)

f ‘(x) = 2x

3.) Begin Newton’s Method iterations at i = 0 with an initial guess of x0 = 5.
Plugging 0 in for i in the Newton’s Method equation, we get:

$$x_{1} = x_{0} \; – \; \frac{f(x_{0})}{f'(x_{0})} \; \Rightarrow \; x_{1} = (5) \; – \; \frac{(5)^2-10}{2 \cdot (5)} \; \Rightarrow \; x_{1} = 3.50000$$
$$\lvert x_{1} \; – \; x_{0} \rvert \leq \varepsilon \; \Rightarrow \; \lvert(3.50000) \; – \; (5)\rvert = 1.50000\text{, }1.50000\nleq0.0001$$
$$\lvert f(x_{1}) \rvert \leq \delta \; \Rightarrow \; \lvert(3.50000)^2-10\rvert = 2.25000\text{, }2.25000\nleq0.0001$$
Convergence criteria not satisfied, continue iterating.

4.) For the next iteration, i = 1. Plugging 1 in for i in the Newton’s Method equation, we get:

$$x_{2} = x_{1} \; – \; \frac{f(x_{1})}{f'(x_{1})} \; \Rightarrow \; x_{2} = (3.50000) \; – \; \frac{(3.50000)^2-10}{2 \cdot (3.50000)} \; \Rightarrow \; x_{2} = 3.17857$$
$$\lvert x_{2} \; – \; x_{1} \rvert \leq \varepsilon \; \Rightarrow \; \lvert(3.17857) \; – \; (3.50000)\rvert = 0.32143\text{, }0.32143\nleq0.0001$$
$$\lvert f(x_{2}) \rvert \leq \delta \; \Rightarrow \; \lvert(3.17857)^2-10\rvert = 0.10332\text{, }0.10332\nleq0.0001$$
Convergence criteria not satisfied, continue iterating.

5.) For the next iteration, i = 2. Plugging 2 in for i in the Newton’s Method equation, we get:

$$x_{3} = x_{2} \; – \; \frac{f(x_{2})}{f'(x_{2})} \; \Rightarrow \; x_{3} = (3.17857) \; – \; \frac{(3.17857)^2-10}{2 \cdot (3.17857)} \; \Rightarrow \; x_{3} = 3.16232$$
$$\lvert x_{3} \; – \; x_{2} \rvert \leq \varepsilon \; \Rightarrow \; \lvert(3.16232) \; – \; (3.17857)\rvert = 0.01625\text{, }0.01625\nleq0.0001$$
$$\lvert f(x_{3}) \rvert \leq \delta \; \Rightarrow \; \lvert(3.16232)^2-10\rvert = 0.00026\text{, }0.00026\nleq0.0001$$
Convergence criteria not satisfied, continue iterating.

6.) For the next iteration, i = 3. Plugging 3 in for i in the Newton’s Method equation, we get:

$$x_{4} = x_{3} \; – \; \frac{f(x_{3})}{f'(x_{3})} \; \Rightarrow \; x_{4} = (3.16232) \; – \; \frac{(3.16232)^2-10}{2 \cdot (3.16232)} \; \Rightarrow \; x_{4} = 3.16228$$
$$\lvert x_{4} \; – \; x_{3} \rvert \leq \varepsilon \; \Rightarrow \; \lvert(3.16228) \; – \; (3.16232)\rvert = 0.00004\text{, }0.00004\leq0.0001$$
$$\lvert f(x_{4}) \rvert \leq \delta \; \Rightarrow \; \lvert(3.16228)^2-10\rvert = 0.00000\text{, }0.00000\leq0.0001$$
Convergence criteria has been satisfied.

How the Calculator Works

This calculator is written in the web programming technologies HTML, CSS, and JavaScript (JS). The HTML builds the framework of the calculator, the CSS styles the framework, and the JS enables interactions with the user and the calculations to happen.

JS runs inside an internet browser just like a program runs inside a computer’s operating system. Since this calculator relies only on JS to perform calculations, it can provide instant solutions to the user.

Inside the JS code that powers this calculator is the same routine outlined throughout this lesson. The user’s inputted initial guess is plugged into the Newton’s Method formula and the new x value is calculated. The convergence criteria formulas are evaluated and compared against the user’s inputted convergence criteria value.

The routine will continue iterating until the convergence criteria are satisfied or the iteration limit is reached. If the convergence criteria are satisfied, the x value from the final iteration is returned as the root of the user’s inputted function. If the iteration limit is reached, the user is informed that the evaluation has diverged and no solution was found.

Scroll to Top