Program for Method Of False Position | JavaScript program for implementation of Bisection Method for solving equations ; An example function whose solution is determined using Bisection Method . The function is x ^ 3 - x ^ 2 + 2 ; Prints root of func ( x ) in interval [ a , b ] ; Initialize result ; Find the point that touches x axis ; Check if the above found point is root ; Decide the side to repeat the steps ; Initial values assumed
let MAX_ITER = 1000000 function func ( x ) { return x * x * x - x * x + 2 ; } function regulaFalsi ( a , b ) { if ( func ( a ) * func ( b ) >= 0 ) { document . write ( " " ) ; return ; } let c = a ; for ( let i = 0 ; i < MAX_ITER ; i ++ ) { c = Math . floor ( ( a * func ( b ) - b * func ( a ) ) / ( func ( b ) - func ( a ) ) ) ; if ( func ( c ) == 0 ) { break ; } else if ( func ( c ) * func ( a ) < 0 ) { b = c ; } else { a = c ; } } document . write ( " " + c ) ; } let a = - 200 ; let b = 300 ; regulaFalsi ( a , b ) ;