Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. def myHorner(dd, xp, x):
  2. n = np.size(xp)
  3. q = dd
  4. for k in range(n-1,0, -1):
  5. q = dd[k-1]+q*(xp-x[k-1])
  6. return q
  7.  
  8.  
  9. def comparaison(f,a,b,n):
  10. xx=np.linspace(a,b,n)
  11. vectab= np.linspace(a,b,n)
  12. for i in range(1,n):
  13.  
  14. x1= a + (i-1)*(b-a)/(n-1)
  15. x2= (a+b)/2 + ((b-a)/2)*cos((2*i-1)*pi/(2*n))
  16. df1=diffdiv(x1 , f(x1))
  17. df2=diffdiv(x2 , f(x2))
  18. p1 = myhorner(df1,x1,xx)
  19. p2 = myhorner(df2,x2,xx)
  20. plt.figure(1)
  21. plt.subplot(211)
  22. vectF=f(vectab)
  23. plt.plot(vectF)
  24. plt.subplot(212)
  25. plt.plot(x1,p1,'o',color='red')
  26. plt.plot(x2,p2,'o',color ='blue')
  27.  
  28. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement