Professional Documents
Culture Documents
Andreabustosvazquez - t1 - Los2 Metodos
Andreabustosvazquez - t1 - Los2 Metodos
Clc
clear
n=length(x);
D=zeros(n,2);
a=zeros(n,1);
a(1)=y(1,1);
x1=3.5;
for i=1:n-1
D(i,1)=(y(i+1,1)-y(i,1))/(x(i+1,1)-x(i,1));
end
for j=2:n-1
for i=1:n-j
D(i,j)=(D(i+1,j-1)-D(i,j-1))/(x(j+1,1)-x(j-1));
end
end
for j=2:n
a(j,1)=D(1,j-1);
end
yint=a(1,1);
xt=1;
for j=2:(n)
xt=xt*(x1-x(j-1,1));
yint=yint+a(j,1)*xt;
end
disp(yint)
%%
%MÉTODO ESTÁNDAR
clc, clear
x1=3.5;
a = [1^6 1^5 1^4 1^3 1^2 1^1 1; 2.5^6 2.5^5 2.5^4 2.5^3 2.5^2 2.5^1 1; 3^6 3^5 3^4 3^3 3^2 3^1
1; 4.5^6 4.5^5 4.5^4 4.5^3 4.5^2 4.5^1 1; 5^6 5^5 5^4 5^3 5^2 5^1 1; 6^6 6^5 6^4 6^3 6^2 6^1 1;
0^6 0^5 0^4 0^3 0^2 0^1 1 ];
sol=a\y;
yint=0;
n=7;
for i=1:n
yint=yint+sol(i,1)*x1^(n-1);
n=n-1;
end
fprintf('y= %g',yint)