Programmers and Teachers:
Newton's Method Calculator
Newton's Method Lesson
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:
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 i in the general equation. This results in:
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:
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:
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.
Calculate the root of f(x) = x2 – 10 using Newton’s Method.
1.) Using the general equation for Newton’s Method:
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:
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
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.