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
No comments:
Post a Comment