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[0])
  12.         for i in range(0,N-1):
  13.             if(xk>=xyvect[0][i] and xk<xyvect[0][i+1]):
  14.                 xinterp.append(xk)
  15.                 yinterp.append(interplin2p(xk,xyvect[0][i],xyvect[1][i],xyvect[0][i+1],xyvect[1][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[0]))
  24. pylab.plot (xyv[0], xyv[1], '.',xyv[0], xyv[1],'-')
  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[0], xyinterp[1], '-',xyv[0], xyv[1], '^r')
  31. pylab.show()
  32.  
  33. print(len(xyinterp[0]))
  34. print(len(xyinterp[1]))
  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[0]))
  43. pylab.plot (xyv[0], xyv[1], '.',xyv[0], xyv[1],'-')
  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[0], xyinterp[1], '-',xyv[0], xyv[1], '^r')
  50. pylab.show()
  51.  
  52. print(len(xyinterp[0]))
  53. print(len(xyinterp[1]))
  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. OK, I Understand
 
Top