Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %ce s-a lucrat inainte
- function a=METNAIVA(X,Y)
- n=length(X)-1
- for i=1:n+1
- for j=1:n+1
- A(i,j)=X(i)^(j-1)
- end
- end
- for i=1:n+1
- Ai=A
- Ai(:,i)=Y(:)
- a(i)=det(Ai)/det(A)
- end
- end
- function lab3
- syms x;
- f(x)=exp(2*x);
- n=3;
- X=linspace(-1,1,n+1)
- Y=f(X)
- ezplot(f,[-1,1])
- hold on
- plot(X,Y,'r+');
- a=METNAIVA(X,Y)
- Pn=0
- for i=1:n+1
- Pn=Pn+(x^(i-1))*a(i);
- end
- ezplot(Pn,[-1,1])
- Pn=inline(Pn,'x')
- Pn(0.1)
- end
- function y=METL(X,Y,x)
- n=length(X)-1;
- Pn=0;
- for k=1:n+1
- L=1;
- for j=1:n+1
- if (j~=k)
- L=L*(x-X(j))/(X(k)-X(j));
- end
- end
- Pn=Pn+L*Y(k);
- end
- y=Pn;
- end
- function lab3b
- syms z;
- f(z)=exp(2*z);
- n=3;
- X=linspace(-1,1,n+1);
- Y=f(X);
- x=linspace(-1,1,1000);
- for i=1:length(x)
- y(i)=METL(X,Y,x(i));
- end
- plot(X,Y,'r+')
- plot(x,y)
- end
- %ce am lucrat eu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement