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 |
import os import matplotlib.pyplot as plt import numpy as np os.chdir('/home/vg/Downloads/projects/ex8') os.getcwd() plt.figure(figsize=(10,8)) x = np.linspace(0,1,500) y = np.sqrt(1-x**2) xp = np.linspace(0,1,6) yp = np.sqrt(1-xp**2) xi = np.arange(0.1,1.0,0.2) yi = np.interp(xi,xp,yp) plt.plot(x,y,'b',label='ideal') plt.plot(xp,yp,'or',label='interpolation points') plt.plot(xp,yp,'--r',label='piecewise linear function') plt.plot(xi,yi,'sg',label='interpolated values') plt.legend(loc='best') plt.grid() plt.axis('scaled') plt.axis([0,1.1,0,1.1]) plt.title('Piecewise linear interpolation') plt.savefig("example8.png", dpi=100) plt.show() plt.close() <img class=" wp-image-63 aligncenter" src="https://gantovnik.com/bio-tips/wp-content/uploads/2018/12/example8.png" alt="example8" width="680" height="544" /> |
Recent Comments