Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import numpy as np
- def f(x):
- return np.log(x)
- x0, x, x1, x2 = 1, 2, 4, 6
- A0 = f(x0)
- A1 = ((f(x1) - f(x0)) / (x1 - x0))
- A2 = (((f(x2) - f(x1)) / (x2 - x1)) - A1) / (x2 - x0)
- result = A0 + A1 * (x - x0) + A2 * ((x - x0) * (x - x1))
- print(result)
- val_x = np.linspace(.01, 5, num = 100)
- plt.plot(val_x, f(val_x), 'b')
- plt.plot(2, result, 'ro')
- plt.plot(2, f(2), 'go')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement