• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Jan 14th, 2020 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import numpy as np
2. import pylab
3.
4. def interplin2p(x,xi,yi,xi1,yi1):
5.     return yi+(yi1-yi)*(x-xi)/(xi1-xi)
6.
7. def interplinvect(x,xyvect):
8.     xinterp=[]
9.     yinterp=[]
10.     for xk in x:
11.         N=len(xyvect)
12.         for i in range(0,N-1):
13.             if(xk>=xyvect[i] and xk<xyvect[i+1]):
14.                 xinterp.append(xk)
15.                 yinterp.append(interplin2p(xk,xyvect[i],xyvect[i],xyvect[i+1],xyvect[i+1]))
16.             i=i+1
17.     return(xinterp,yinterp)
18.
19. xyv=[]
20. xyv.append([i for i in np.arange(0.1,3.3,0.1)])
21. xyv.append([np.cos(1/i) for i in np.arange(0.1,3.3,0.1)])
22. print(xyv)
23. print(len(xyv))
24. pylab.plot (xyv, xyv, '.',xyv, xyv,'-')
25. pylab.show()
26.
27. xin=[i for i in np.arange(0,3.3,0.08)]
28. xyinterp = interplinvect(xin,xyv)
29. print(xyinterp)
30. pylab.plot(xyinterp, xyinterp, '-',xyv, xyv, '^r')
31. pylab.show()
32.
33. print(len(xyinterp))
34. print(len(xyinterp))
35. print(len(xin))
36.
37.
38. del xyv[:]
39. xyv.append([i for i in np.arange(0.1,3.3,0.1)])
40. xyv.append([np.exp(np.sin(i)) for i in np.arange(0.1,3.3,0.1)])
41. print(xyv)
42. print(len(xyv))
43. pylab.plot (xyv, xyv, '.',xyv, xyv,'-')
44. pylab.show()
45.
46. xin=[i for i in np.arange(0.1,3.3,0.08)]
47. xyinterp = interplinvect(xin,xyv)
48. print(xyinterp)
49. pylab.plot(xyinterp, xyinterp, '-',xyv, xyv, '^r')
50. pylab.show()
51.
52. print(len(xyinterp))
53. print(len(xyinterp))
54. print(len(xin))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top