Академический Документы
Профессиональный Документы
Культура Документы
TAREA EXTRA
CARLOS JARAMILLO
13 de Noviembre de 2013
1
Carlos Jaramillo
Mtodos Numricos
CDIGO EN MATLAB
Interpolacion de newton
clear;clc;
disp('Metodos Numericos');
disp('interpolacion de newton');
n=input('ingrese el grado del polinomio, n=');
fprintf('Se necesitan %.0f puntos\n',n+1);
disp('ingrese los puntos');
for i=1:n+1
fprintf('x%.0f=',i-1);
X(i)=input(' ');
fprintf('y%.0f=',i-1);
Y(i)=input(' ');
end
DD=zeros(n+1);
DD(:,1)=Y;
for k=2:n+1
for J=k:n+1
DD(J,k)=[DD(J,k-1)-DD(J-1,k-1)]/[X(J)-X(J-k+1)];
end
end
disp('La matriz tabulada es:');
disp(DD);
disp('El polinomio interpolador de newton es');
syms x;
polnew=DD(1,1);
P=1;
for i=1:n
P=P*(x-X(i));
polnew=polnew+P*DD(i+1,i+1);
end
polnew=expand(polnew);
pretty(polnew);
%x=input('ingrese el valor de x a interpolar,x=');
%vi=eval(polnew);
%fprintf('el valor interpolado es %.2f\n',vi);
hold on;
ezplot(polnew,[X(1) X(n+1)]);
%plot(x,vi,'r+');
2
Carlos Jaramillo
Mtodos Numricos
RESULTADO
Metodos Numericos
interpolacion de newton
ingrese el grado del polinomio, n=5
Entonces se necesitan 6 puntos
ingrese los puntos
x0= 1
y0= -3
x1= 2
y1= 0
x2= 3
y2= 15
x3= 4
y3= 48
x4= 5
y4= 105
x5= 6
y5= 192
3
Carlos Jaramillo
Mtodos Numricos
15
15
48
33
105
57
12
192
87
15
-4x
GRAFICA
4
Carlos Jaramillo
Mtodos Numricos
Mtodos Numricos
DD=zeros(n+1);
DD(:,1)=Y;
for k=2:n+1
for J=k:n+1
DD(J,k)=[DD(J,k-1)-DD(J-1,k-1)]/[X(J)-X(J-k+1)];
end
end
disp('La matriz tabulada es:');
disp(DD);
disp('Los polinomios interpoladores por splin son);
syms x;
polnew=DD(1,1);
P=1;
for i=1:n;
hold on;
plot (X(1,i),X(2,i),'*','MarkerEdgeColor','r','LineWidth',1);
title('Interpolacin por "splines" de orden 3.');
end
EJEMPLO
Mtodos Numricos
-6-1.8960x+18.8723x2 -8.9763x3
2+8.9196x- 8.0567x2 +1.1371x3
4-3.7826x-4.6455x2 +4.4281x3
0+0.2107x+8.6388x2 -4.8495x3
4+2.9398x-5.9097x2 +0x3
GRAFICA RESULTANTE
7
Carlos Jaramillo
Mtodos Numricos
CODIGO MATLAB
% SPLINE LINEAL
function [m,b]=spline(X)
X= [1 2 3 4 5 6 7 8 9; 0 3 4 -6 2 4 0 4 3]
n=length(X(1,:));
for i=1:n-1;
m(i)=(X(2,i+1)-X(2,i))/(X(1,i+1)-X(1,i))
b(i)=X(2,i);
x=X(1,i):X(1,i+1);
y=m(i)*(x-X(1,i))+b(i)
hold on;
plot(x,y,'b');
end
for i=1:n;
hold on;
plot (X(1,i),X(2,i),'*','MarkerEdgeColor','r','LineWidth',1);
title('Interpolacin por "splines" de orden 1.');
end
DD=zeros(n+1);
DD(:,1)=Y;
for k=2:n+1
for J=k:n+1
DD(J,k)=[DD(J,k-1)-DD(J-1,k-1)]/[X(J)-X(J-k+1)];
end
end
disp('La matriz tabulada es:');
disp(DD);
disp('Los polinomios interpoladores por splin lineal son);
syms x;
polnew=DD(1,1);
8
Carlos Jaramillo
Mtodos Numricos
9
Carlos Jaramillo