Advertisement
icatalin

Lab 4 19.04

Apr 19th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. function Hermitescript
  2. %% reprezentarea grafica a pol
  3. fp=inline('2*exp(2*x)','x');
  4. f=inline('exp(2*x)','x');
  5. fprintf('Functia interpolata este: \n')
  6. disp(f);
  7. fprintf('Nodurile de interpolare sunt: \n')
  8. disp (x); disp(Y);
  9. n=2;
  10. X=linspace(-1,1,n+1);
  11. Y=f(X);
  12. Yp=fp(X);
  13. x=linspace(-1,1,100);
  14.  
  15. for i=1:100
  16. Her(i)=Hermite(X,Y,Yp,x(i));
  17. end
  18.  
  19. plot(X,Y,'o','MarkerFaceColor','g');
  20. hold on;
  21. plot(x,Her);
  22.  
  23. %% Reprez. grafica a derivatei H2n+1
  24. figure (2)
  25. dher=diff(Her)./diff(x);
  26. plot(x(1:length(x)-1),dher);
  27. hold on
  28. plot(X,Yp,'o');
  29.  
  30. function y=SplineL(X,Y,x)
  31. n=length(X);
  32. for j=1:(n-1)
  33. a(j)=Y(j);
  34. b(j)=(Y(j+1)-Y(j))/(X(j+1)-X(j));
  35. end
  36. for j=1:(n-1)
  37. if x>=X(j) & x<=X(j+1)
  38. S=a(j)+b(j)*(x-X(j));
  39. break;
  40. end
  41. end
  42. y=S;
  43. end
  44.  
  45. %% metoda hermite de determinare a polinomului H2n+1
  46. function y = Hermite(X,Y,Yp,x)
  47.  
  48. n = length(X)-1;
  49. Her=0;
  50.  
  51. for k=1:(n+1)
  52. L=1;Lp=0;
  53. for j=1:(n+1)
  54. if j~=k
  55. L=L*(x-X(j))/(X(k)-X(j));
  56. Lp=Lp+1/(X(k)-X(j));
  57. end
  58. end
  59.  
  60. H=L*L*(1-2*Lp*(x-X(k)));
  61. K=L*L*(x-X(k));
  62. Her=Her+H*Y(k)+K*Yp(k);
  63.  
  64. end
  65.  
  66. y=Her;
  67.  
  68. end
  69.  
  70. %in loc de Hermite(...) ii dam apel cu functia asta
  71. function y=SplineL(X,Y,x)
  72. n=length(X);
  73.  
  74. for j=1:(n-1)
  75. a(j)=Y(j);
  76. b(j)=(Y(j+1)-Y(j))/(X(j+1)-X(j));
  77. end
  78.  
  79. for j=1:(n-1)
  80. if x>=X(j) & x<=X(j+1)
  81. S=a(j)+b(j)*(x-X(j));
  82. break;
  83. end
  84. end
  85.  
  86. y=S;
  87.  
  88. end
  89.  
  90. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement