Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- import pandas as pd
- import re
- from scipy.spatial.distance import cosine as cos
- import collections
- def f(x):
- return np.sin(x / 5) * np.exp(x / 10) + 5 * np.exp(-x / 2)
- A = np.array([[1, 1, 1, 1], [64, 16, 4, 1], [1000, 100, 10, 1], [3375, 225, 15, 1]])
- b = np.array([f(1), f(4), f(10), f(15)])
- res = np.linalg.solve(A, b)
- print(res[::-1])
- def g(x):
- global res
- return res[0] * x * x * x + res[1] * x * x + res[2] * x + res[3]
- x = np.arange(0, 17, 0.5)
- y = np.array([f(i) for i in x])
- plt.plot(x, y)
- y = np.array([g(i) for i in x])
- plt.plot(x, y)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment