Roots of High-Degree Equations Equations can be polynomials, radicals, trigonometric, logarithmic, and other. Simplest example is the quadratic function. More complex equations will often require numerical methods to solve. Newton Raphson Method algorithm: - similar to Simple Iteration except it handles the equation as a function, not a rearrangement - first step is to put the equation as a function - second step is to calculate the first derivative of the function - third step is to iterate as the simple iteration method This method is an optimization of the simple iteration method. for example:
''' for equation: x^3 - x^2 + 7 = 10 x^3 - x^2 - 3 = 0 derivative 3x^2 - 2x = 0 Newton Raphson equation: y = x - (x^3 - x^2 - 3) / (3x^2 - 2x) ''' x = 2 # initial guess, derive multiple roots with different guesses for i in range(100): y = x - (x^3 - x^2 - 3) / (3x^2 - 2x) if x == y:# or within tolerable range break x = y # y now approximates the value of the root
Equations of higher-degree equations can be polynomials, radicals, trigonometric, logarithmic, and other. Simplest example is the quadratic function. More complex equations will often require numerical methods to solve. Simple Iterations Method Algorithm: - based on trial and error, values are substituted until root is obtained - first step is to REARRANGE the equation to isolate the variable to the left side of the equation - second step is to ASSUME an initial trial value for the first iteration - third step is to SUBSTITUTE the value in the equation and solve - fourth step is to REPLACE the value if the value does not solve the equation else BREAK - fifth step is to REPEAT the third and fourth steps with the NEW VALUE of the equation
''' for equation: x^3 - x^2 + 7 = 10 x(x^2 - x) = 3 x = 3 / (x^2 - x) ''' def tolerable_range(x, y, tolerance=0.001): pass # can be difference: abs(x, y) < tolerance # can be analysis of convergence #(i.e. difference from previous value is nominal) def check_divergence(x, y): pass # if divergence exists, solution cannot be solved # example implementation: # https://gist.github.com/zhiyzuo/f80e2b1cfb493a5711330d271a228a3d x = 2 # initial guess for i in range(100): y = 3 / (x^2 - x) # new value if x == y:# or within tolerable range break x = y # y should now approximates the value of the root