Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Lagrange
- function lagrange
- x=[-1 0 1];
- y=[10 7 6];
- p=lagint1(x,y)
- polyval(p,x)
- p=lagint2(x,y)
- polyval(p,x)
- function p=lagint1(x,y)
- p=zeros(1,length(x));
- t=-1:0.1:1;
- for i=1:length(x)
- pi=deconv(poly(x),poly(x(i)));
- Li=pi/polyval(pi,x(i));
- plot(t,polyval(Li,t),t,y(i)*polyval(Li,t));
- hold on;
- p=p+y(i)*Li;
- end
- plot(t,polyval(p,t));
- function p=lagint2(x,y)
- n=length(x);
- X=repmat(x',1,n).^repmat((n-1):-1:0,n,1); %wandermond mátrix
- p=zeros(1,n);
- for i=1:n;
- temp=X;
- temp(:,i)=y;
- p(i)=det(temp)/det(X); %wandermond determináns
- end
- hold off;
- t=-1:0.1:1;
- plot(t,polyval(p,t));
- hold on;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement