Professional Documents
Culture Documents
Lagrange Solution
Lagrange Solution
MATLAB
clc
clear all
n= input('Please input the number of data points = ');
for i=1:n
x=input('Please input x-Datas = ');
X(i)=x
end
for i=1:n
y=input('please input y-Datas= ');
Y(i)=y
end
syms x ;
T=0;
for i=1:n
Z=Y(i)
for j=1:n
if i~=j
Z=Z*(x-X(j))/(X(i)-X(j));
end
end
T=T+Z
end
ezplot(T,[X(1) X(n)])
grid on
problem-3
i
Xi
F(Xi)
1
0
0.9162
2
0.25
0.8109
3
0.5
0.6931
4
0.75
0.5596
5
1.0
0.4055
T=-8/3*(-4581/1250*x+4581/5000)*(x-1/2)*(x-3/4)*(x-1)-21624/625*x*(x1/2)*(x-3/4)*(x-1)+27724/625*x*(x-1/4)*(x-3/4)*(x-1)-44768/1875*x*(x-1/4)*(x1/2)*(x-1)+1622/375*x*(x-1/4)*(x-1/2)*(x-3/4)
``````````````````````````````````````````````````````````````````````````````````````````````````````````````````
Problem-6
i
Xi
F(Xi)
0
0
0
1
/8
0.1502
2
/4
0.5551
3
3/8
0.10879
4
/2
1.57