Lagrange

syms x

x1=[24 40 64 80];

y1=[0.098 0.172 0.257 0.290];

xk=[14 45 59 70];


L0=((x-x1(2))*(x-x1(3))*(x-x1(4)))/((x1(1)-x1(2))*(x1(1)-x1(3))*(x1(1)-x1(4)));

L1=((x-x1(1))*(x-x1(3))*(x-x1(4)))/((x1(2)-x1(1))*(x1(2)-x1(3))*(x1(2)-x1(4)));

L2=((x-x1(1))*(x-x1(2))*(x-x1(4)))/((x1(3)-x1(1))*(x1(3)-x1(2))*(x1(3)-x1(4)));

L3=((x-x1(1))*(x-x1(2))*(x-x1(3)))/((x1(4)-x1(1))*(x1(4)-x1(2))*(x1(4)-x1(3)));


L=L0*y1(1) + L1*y1(2) + L2*y1(3) + L3*y1(4);

L


i=1;

while i<=4

L0=((xk(i)-x1(2))*(xk(i)-x1(3))*(xk(i)-x1(4)))/((x1(1)-x1(2))*(x1(1)-x1(3))*(x1(1)-x1(4)));

L1=((xk(i)-x1(1))*(xk(i)-x1(3))*(xk(i)-x1(4)))/((x1(2)-x1(1))*(x1(2)-x1(3))*(x1(2)-x1(4)));

L2=((xk(i)-x1(1))*(xk(i)-x1(2))*(xk(i)-x1(4)))/((x1(3)-x1(1))*(x1(3)-x1(2))*(x1(3)-x1(4)));

L3=((xk(i)-x1(1))*(xk(i)-x1(2))*(xk(i)-x1(3)))/((x1(4)-x1(1))*(x1(4)-x1(2))*(x1(4)-x1(3)));

Disp(‘L(i) =’) L

i=i+1;

end




syms x

x1=[24 40 64 80];

y1=[0.098 0.172 0.257 0.290];

xk=[14 45 59 70];


L0=((x-x1(2))*(x-x1(3))*(x-x1(4)))/((x1(1)-x1(2))*(x1(1)-x1(3))*(x1(1)-x1(4)));

L1=((x-x1(1))*(x-x1(3))*(x-x1(4)))/((x1(2)-x1(1))*(x1(2)-x1(3))*(x1(2)-x1(4)));

L2=((x-x1(1))*(x-x1(2))*(x-x1(4)))/((x1(3)-x1(1))*(x1(3)-x1(2))*(x1(3)-x1(4)));

L3=((x-x1(1))*(x-x1(2))*(x-x1(3)))/((x1(4)-x1(1))*(x1(4)-x1(2))*(x1(4)-x1(3)));


L=L0*y1(1) + L1*y1(2) + L2*y1(3) + L3*y1(4);

L


przedzial=[14 70];

ezplot(L,przedzial);


i=1;

while i<=4

L0=((xk(i)-x1(2))*(xk(i)-x1(3))*(xk(i)-x1(4)))/((x1(1)-x1(2))*(x1(1)-x1(3))*(x1(1)-x1(4)));

L1=((xk(i)-x1(1))*(xk(i)-x1(3))*(xk(i)-x1(4)))/((x1(2)-x1(1))*(x1(2)-x1(3))*(x1(2)-x1(4)));

L2=((xk(i)-x1(1))*(xk(i)-x1(2))*(xk(i)-x1(4)))/((x1(3)-x1(1))*(x1(3)-x1(2))*(x1(3)-x1(4)));

L3=((xk(i)-x1(1))*(xk(i)-x1(2))*(xk(i)-x1(3)))/((x1(4)-x1(1))*(x1(4)-x1(2))*(x1(4)-x1(3)));


Lx=L0*y1(1) + L1*y1(2) + L2*y1(3) + L3*y1(4);

Lx

i=i+1;

end


Wyszukiwarka