Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Hermitescript
- %% reprezentarea grafica a pol
- fp=inline('2*exp(2*x)','x');
- f=inline('exp(2*x)','x');
- fprintf('Functia interpolata este: \n')
- disp(f);
- fprintf('Nodurile de interpolare sunt: \n')
- disp (x); disp(Y);
- n=2;
- X=linspace(-1,1,n+1);
- Y=f(X);
- Yp=fp(X);
- x=linspace(-1,1,100);
- for i=1:100
- Her(i)=Hermite(X,Y,Yp,x(i));
- end
- plot(X,Y,'o','MarkerFaceColor','g');
- hold on;
- plot(x,Her);
- %% Reprez. grafica a derivatei H2n+1
- figure (2)
- dher=diff(Her)./diff(x);
- plot(x(1:length(x)-1),dher);
- hold on
- plot(X,Yp,'o');
- function y=SplineL(X,Y,x)
- n=length(X);
- for j=1:(n-1)
- a(j)=Y(j);
- b(j)=(Y(j+1)-Y(j))/(X(j+1)-X(j));
- end
- for j=1:(n-1)
- if x>=X(j) & x<=X(j+1)
- S=a(j)+b(j)*(x-X(j));
- break;
- end
- end
- y=S;
- end
- %% metoda hermite de determinare a polinomului H2n+1
- function y = Hermite(X,Y,Yp,x)
- n = length(X)-1;
- Her=0;
- for k=1:(n+1)
- L=1;Lp=0;
- for j=1:(n+1)
- if j~=k
- L=L*(x-X(j))/(X(k)-X(j));
- Lp=Lp+1/(X(k)-X(j));
- end
- end
- H=L*L*(1-2*Lp*(x-X(k)));
- K=L*L*(x-X(k));
- Her=Her+H*Y(k)+K*Yp(k);
- end
- y=Her;
- end
- %in loc de Hermite(...) ii dam apel cu functia asta
- function y=SplineL(X,Y,x)
- n=length(X);
- for j=1:(n-1)
- a(j)=Y(j);
- b(j)=(Y(j+1)-Y(j))/(X(j+1)-X(j));
- end
- for j=1:(n-1)
- if x>=X(j) & x<=X(j+1)
- S=a(j)+b(j)*(x-X(j));
- break;
- end
- end
- y=S;
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement