
%%1
clc;
X=[2 2.5 4 1];
Y=[0.5 0.4 0.25 1];
Lagrange(X,Y);

%

%%2
clc,clear;
%X=[2 2.5 4 1];
%Y=[0.5 0.4 0.25 1];
%Lagrange(X,Y);
 
X=-5:1:5
Y=sin(X)
L=Lagrange(X,Y);
t=linspace(-5,5,1001);
GroundTruth=sin(t);
 
x=t
P=eval(L)
 
figure,plot(t,GroundTruth,'m:')
hold on, plot(t,P,'-b')
plot(X,Y,'r+')
legend('sin(x)','Lagrange','point')

%


%%3
clc,clear;
%X=[2 2.5 4 1];
%Y=[0.5 0.4 0.25 1];
%Lagrange(X,Y);
 
X1=-5:1:5;
X2=-5:0.5:5;
X3=-5:0.2:5;
 
 
Y1=sin(X1);
Y2=sin(X2);
Y3=sin(X3);
 
L1=Lagrange(X1,Y1);
L2=Lagrange(X2,Y2);
L3=Lagrange(X3,Y3);
 
t=linspace(-5.6,5.6,1001);
GroundTruth=sin(t);
 
x=t;
 
P1=eval(L1);
P2=eval(L2);
P3=eval(L3);
 
figure,plot(t,GroundTruth,'m-')
hold on, plot(t,P1,':b')
hold on, plot(t,P2,':r')
hold on, plot(t,P3,':g')
plot(X1,Y1,'r+')
legend('sin(x)','Lagrange-1','Lagrange-0.5','Lagrange-0.2','point')



