import numpy as np import pypolint from matplotlib.pyplot import * xa = np.linspace(0, 1, 30) ya = np.sin(xa + np.square(xa)) xx = np.linspace(-0.5, 1.5, 600) yy = np.sin(xx + np.square(xx)) n = 5 [y1, dy1] = pypolint.nearestpolint(xa, ya, n, xx) n = 8 [y2, dy2] = pypolint.nearestpolint(xa, ya, n, xx) n = 12 [y3, dy3] = pypolint.nearestpolint(xa, ya, n, xx) figure(1) plot(xa, ya, 'g*', label='Table Values') plot(xx, y1, '-', label='4th order interpolation') plot(xx, y2, 'r-', label='7th order interpolation') plot(xx, y3, 'k-', label='11th order interpolation') xlabel('x') ylabel('Predicted y values') legend(loc=3) figure(2) gca().set_yscale('log') plot(xx, abs(y1 - yy), 'b-', label='4th order interpolation') plot(xx, abs(y2 - yy), 'r-', label='7th order interpolation')
import numpy as np import pypolint from matplotlib.pyplot import * xa = np.linspace(0, 1, 5) ya = np.sin(xa + np.square(xa)) n = 5 xx = np.linspace(-0.5, 1.5, 200) yy = np.sin(xx + np.square(xx)) [y, dy] = pypolint.nearestpolint(xa, ya, n, xx) figure(1) plot(xa, ya, 'k*', label='Theoretical Values') plot(xx, y, '-', label='4th order interpolation') xlabel('x') ylabel('Predicted y values') legend(loc=3) figure(2) gca().set_yscale('log') plot(xx, abs(y - yy), '-') xlabel('x') ylabel('Error (measured against theoretical value)') show()
ya=np.zeros_like(xa) for i in range(1,6): j=2*i+1 ya=ya+np.sin(j*xa)/j return ya pi=np.pi xa=np.linspace(-pi,pi,101) ya=fx(xa) xx=np.linspace(0,2*pi,999) yy=fx(xx) maxdy=np.zeros(18) for n in range(3,21): print n [y,dy]=pypolint.nearestpolint(xa,ya,n,xx) maxdy[n-3]=max(abs(y-yy)) print maxdy # figure(0) # plot(xx[0:500],yy[0:500],'g-') # plot(xx[0:500],y[0:500],'-') # figure(1) # plot(xx,yy,'g-') # plot(xx,y,'-') # figure(2) # gca().set_yscale('log') # plot(xx,abs(y-yy))
import numpy as np import pypolint from matplotlib.pyplot import * xa=np.linspace(0,1,30) xb=np.linspace(0,1,5) ya=np.sin(xa+np.square(xa)) yb=np.sin(xb+np.square(xb)) n=5 xx=np.linspace(-0.5,6.5,1000) yy=np.sin(xx+np.square(xx)) [y,dy]=pypolint.nearestpolint(xa,ya,n,xx) [y1,dy1]=pypolint.nearestpolint(xb,yb,n,xx) figure(1) plot(xa,ya,'k*',label='Table Values') plot(xx,y1,'r-',label='5 sample interpolation') plot(xx,y,'-',label='30 sample interpolation') xlabel('x') ylabel('Predicted y values') legend(loc=3) figure(2) gca().set_yscale('log') plot(xx,abs(y1-yy),'r-',label='5 samples') plot(xx,abs(y-yy),'-',label='30 samples') xlabel('x') ylabel('Error (measured against theoretical value)') legend(loc=3) show()
import numpy as np import pypolint from matplotlib.pyplot import * xa=np.linspace(0,1,30) ya=np.sin(xa+np.square(xa)) xx=np.linspace(-0.5,1.5,600) yy=np.sin(xx+np.square(xx)) n=5 [y1,dy1]=pypolint.nearestpolint(xa,ya,n,xx) n=8 [y2,dy2]=pypolint.nearestpolint(xa,ya,n,xx) n=12 [y3,dy3]=pypolint.nearestpolint(xa,ya,n,xx) figure(1) plot(xa,ya,'g*',label='Table Values') plot(xx,y1,'-',label='4th order interpolation') plot(xx,y2,'r-',label='7th order interpolation') plot(xx,y3,'k-',label='11th order interpolation') xlabel('x') ylabel('Predicted y values') legend(loc=3) figure(2) gca().set_yscale('log')
import numpy as np import pypolint from matplotlib.pyplot import * xa = np.linspace(0, 1, 30) xb = np.linspace(0, 1, 5) ya = np.sin(xa + np.square(xa)) yb = np.sin(xb + np.square(xb)) n = 5 xx = np.linspace(-0.5, 6.5, 1000) yy = np.sin(xx + np.square(xx)) [y, dy] = pypolint.nearestpolint(xa, ya, n, xx) [y1, dy1] = pypolint.nearestpolint(xb, yb, n, xx) figure(1) plot(xa, ya, 'k*', label='Table Values') plot(xx, y1, 'r-', label='5 sample interpolation') plot(xx, y, '-', label='30 sample interpolation') xlabel('x') ylabel('Predicted y values') legend(loc=3) figure(2) gca().set_yscale('log') plot(xx, abs(y1 - yy), 'r-', label='5 samples') plot(xx, abs(y - yy), '-', label='30 samples') xlabel('x') ylabel('Error (measured against theoretical value)') legend(loc=3) show()