1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import os import matplotlib.pyplot as plt import numpy as np from scipy.interpolate import spline os.chdir('/home/vg/Downloads/projects/ex11') os.getcwd() plt.figure(figsize=(10,8)) xp = np.linspace(0,1,6) yp = np.sqrt(1-xp**2) xi = np.linspace(0,1,100) yi = np.interp(xi,xp,yp) ys = spline(xp,yp,xi) plt.plot(xp,yp,'o',label='given points',lw=2) plt.plot(xi,yi,'--',label='piecewise linear',lw=2) plt.plot(xi,ys,'-',label='spline',lw=2) plt.legend(loc='best') plt.grid() plt.xlabel('x') plt.ylabel('y') plt.title(r'Spline interpolation of $y=\sqrt{1-x^2}$') plt.axis('scaled') plt.axis([0,1.2,0,1.2]) plt.savefig("example11.png", dpi=100) plt.show() plt.close() <img class=" wp-image-74 aligncenter" src="https://gantovnik.com/bio-tips/wp-content/uploads/2018/12/example11.png" alt="example11" width="636" height="509" /> |
Recent Comments