Legendre polynomial
#!/usr/bin/env python import numpy as np import matplotlib.pyplot as plt data = np.array(((-9, 5), (-4, 2), (-1, -2), (7, 9)), dtype=float) xcoords = np.linspace(-10, 10, 201) pts = np.arange(0, len(data)) l_x = [] for x in xcoords: l_j = [] for j in pts: lval = 1.0 for m in np.r_[pts[:j], pts[j + 1:]]: x_m, x_j = data[[m, j], 0] lval *= (x - x_m) / (x_j - x_m) l_j.append(lval) l_x.append(np.dot(data[:, 1], l_j)) plt.plot(xcoords, l_x) plt.plot(data[:, 0], data[:, 1], 'o') plt.show()
Finite difference coefficient - Wikipedia
https://doi.org/10.1090/S0025-5718-1988-0935077-0
Radial grid
#!/usr/bin/env python import numpy as np from matplotlib.patches import Circle import matplotlib.pyplot as plt # ln(r_n+1) = ln(r_n) + h # h = 1, r_0 = 1 ln_r = np.arange(11) radii = np.exp(ln_r) fig, ax = plt.subplots() for r in radii: ax.add_patch(Circle((0, 0), radius=r, fill=False)) plt.axis('scaled') ax.set_aspect('equal') plt.show()