Program for Newton Raphson Method | JavaScript program for implementation of Newton Raphson Method for solving equations ; An example function whose solution is determined using Bisection Method . The function is x ^ 3 - x ^ 2 + 2 ; Derivative of the above function which is 3 * x ^ x - 2 * x ; Function to find the root ; x ( i + 1 ) = x ( i ) - f ( x ) / f '(x) ; Initial values assumed
let EPSILON = 0.001 ; function func ( x ) { return x * x * x - x * x + 2 ; } function derivFunc ( x ) { return 3 * x * x - 2 * x ; } function newtonRaphson ( x ) { let h = func ( x ) / derivFunc ( x ) ; while ( Math . abs ( h ) >= EPSILON ) { h = func ( x ) / derivFunc ( x ) ; x = x - h ; } document . write ( " " + " " + Math . round ( x * 100.0 ) / 100.0 ) ; } let x0 = - 20 ; newtonRaphson ( x0 ) ;