You are on page 1of 2

%%time

A = [1, 0.1, 0.01; 1, 0.6, 0.36; 1, 0.8, 0.64]


B = [1.221, 3.320, 4.953];

[L U] = lu(A)

y = L\B';
a = U\y;

P = [0,0,1;0,1,0;1,0,0];
a = a'*P;

polyval(a, 0.2)

A =

1.000000 0.100000 0.010000


1.000000 0.600000 0.360000
1.000000 0.800000 0.640000

L =

1.00000 0.00000 0.00000


1.00000 0.71429 1.00000
1.00000 1.00000 0.00000

U =

1.00000 0.10000 0.01000


0.00000 0.70000 0.63000
0.00000 0.00000 -0.10000

ans = 1.4141
Time: 0.016495704650878906 seconds.

Polinomio de lagrange

n=2;
x = [0.1, 0.6, 0.8];
y = [1.221, 3.320, 4.953];
z=0.2;
p=0;
for i= 1:(n+1)
c=1;
d=1;

for j= 1:(n+1)
if i~=j
c = c*(z-x(j));
d = d*(x(i)-x(j));
end
end
p = p + y(i)* c/d
end

p = 0.83726
p = 2.8293
p = 1.4141

You might also like