Find the zero of the linear function straight line interpolation in Python

''' root = linInterp(f,x1,x2).
    Finds the zero of the linear function f(x) by straight
    line interpolation based on x = x1 and x2.
'''
def linInterp(f,x1,x2):
    f1 = f(x1)
    f2 = f(x2)
    return x2 - f2*(x2 - x1)/(f2 - f1)

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.