##### Related Content

# Newton's Method Calculator

_{0}):

*f '(x) = ...*

**Voovers+ Full Solution Steps Preview:**

## 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.**

### Why do we Learn Newton's Method?

One of the many real-world uses for Newton’s Method is calculating if an asteroid will encounter the Earth during its orbit around the Sun.

All objects in orbit around the Sun have an elliptical orbit, where the size and shape of the ellipse are unique to each respective astronomical object. The standard equation form for an ellipse is given as:

$$ \frac{x^{2}}{a^{2}} + \frac{y^{2}}{b^{2}} = 1 $$

Since an ellipse is represented by this nonlinear equation form and the path of the Earth and asteroid are each represented by their own unique ellipse equation, the two objects’ paths around the Sun are in fact a system of nonlinear equations which can be solved to find intersection points.

Typically, we learn Newton’s Method in the context of finding the roots/zeroes of an equation. However, Newton’s Method is so powerful that it can also be used to solve a system of equations, linear and nonlinear.

Once we are comfortable using Newton’s Method for a single equation, we can set up a modified version of the method to solve our Earth/asteroid system of nonlinear ellipse equations. If any intersection points are found, we can use other orbital mechanics equations to determine when each object will reach those intersection points.

If there are no intersection points, the asteroid will not encounter the Earth. If there are intersection points but the asteroid and Earth reach them at different times, the asteroid will not encounter the Earth. If there are intersection points and the asteroid and Earth do reach them at the same time, the asteroid could encounter the Earth.

### 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 *x _{i + 1}* is the

*x*value being calculated for the new iteration,

*x*is the

_{i}*x*value of the previous iteration,

*f(x*is the function’s value at

_{i})*x*, and

_{i}*f ‘(x*is the value of the function’s derivative at

_{i})*x*.

_{i}For the first iteration *i = 0* we will plug *0* in for *i *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 *x _{0}*. 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 = x _{0}.* Plug

*x*,

_{0}*f(x*, and

_{0})*f ‘(x*into the equation to find

_{0})*x*. We have now completed the first iteration and must determine if more iterations are necessary.

_{1}**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 *x _{i + 1}* is the

*x*value being calculated for the new iteration,

*x*is the

_{i}*x*value of the previous iteration,

*ε*is the desired precision (closeness of successive x values),

*f(x*is the function’s value at

_{i+1})*x*, and

_{i+1}*δ*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)* = *x*^{2} – 10 using Newton’s Method.

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

Convergence when:

Using *ε *= 0.0001 and *δ *= 0.0001

2.) Given *f(x)* = *x ^{2}* – 10, find

*f ‘(x)*

*f ‘(x)* = 2*x*

3.) Begin Newton’s Method iterations at *i* = 0 with an initial guess of *x _{0}* = 5.

Plugging 0 in for

*i*in the Newton’s Method equation, we get:

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

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

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

## 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.