Está en la página 1de 6

UNIVERSIDAD NACIONAL MAYOR DE SAN MARCOS

FACULTAD DE INGENIERÍA DE SISTEMAS E INFORMÁTICA


ASIGNATURA: Métodos Numéricos
CICLO: 2019-I
TIEMPO: 90 minutos

PRÁCTICA CALIFICADA 01
GRUPO APELLIDOS Y NOMBRES
3 Espinoza Quispe Jairo Cesar

3 Gonzales Ayvar Luis Felipe

INDICACIONES:
 Desarrolle la prueba siguiendo las indicaciones y los métodos sugeridos. Plantee la solución en su hoja de examen, sea claro y
ordenado.
 Puede utilizar octave. No se permite ningún otro instrumento o aplicación, esta conlleva a la anulación de la prueba.
 Copiar los resultados intermedios del octave en la solución del problema en forma de texto, salvo que sea un gráfico.
 Copiar en la solución del problema el programa utilizado en Octave.
 Para el cálculo de todos los problemas use 8 decimales.

Problema 01.
a)Aproximando la talla de un infante de 17 meses empleando la información de los dieciocho primeros meses

Usando el código:

clear ;
clc;
i=1;
matri=[0,50.3;3,60;6,67;9,72;12,76;15,79;18,82.5];
x=17;
suma=0;
while i<=7
j=1;
partesuperior=1;
parteinferior=1;
while j<=7
if j!=i
partesuperior=partesuperior*(x-matri(j,1));
parteinferior=parteinferior*(matri(i,1)-matri(j,1));
endif
j++;
endwhile
suma=suma+matri(i,2)*partesuperior/parteinferior;
i++;
endwhile
disp(suma)
La talla es : 80.959 es el valor del polinomio de LaGrange evaluado en 17 mesess.
c)
CODIGO OCTAVE : METODO NEWTON
clear;
clc
x=[3 6 9 12 15 18 24];
y=[6.2 8 9.2 10.2 11.1 11.8 12.9];
%Cuerpo del programa
xa=x;
ya=y;
%formaicón de las diferencias divididas
d=zeros(length(y));
d(:,1)=y';
for k=2 : length(x)
for j=1 : length(x)+1-k
d(j,k)=(d(j+1,k-1)-d(j,k-1))/(x(j+k-1)-x(j));
end
end
M=[x' d];
disp('x y');
disp(M);
%Formación del polinomio
for w=1:length(x)
ds=num2str(abs(d(1,w)));
if(w>1)
if x(w-1)<0
sg1='+';
else
sg1='-';
end
end
if d(1,w)<0
sg2='-';
else
sg2='+';
end
if w==1
acum=num2str(d(1,1));
elseif w==2
polact=['(x' sg1 num2str(abs(x(w-1))) ')' ];
actual=[ds '*' polact];
acum=[acum sg2 actual];
else
polact=[polact '.*' '(x' sg1 num2str(abs(x(w-1))) ')' ];
actual= [ds '*' polact];
acum=[acum sg2 actual];
end
end
%PResultados
fprintf('\n Valores de X e Y \n ');
disp(xa);
disp(ya);
fprintf('\n Polinomio interpolacion newton : %s \n',acum);
x=input(' X interp = ');
if x>max(xa) || x<min(xa)
fprintf('\n Punto fuera de rango. El resultado puede ser equivodado \n');
end
xinterp=x;
yinterp=eval(acum);
fprintf(' Y(%g) \n',x,yinterp);

RESULTADO
x y
3.00000 6.20000 0.60000 -0.03333 0.00247 -0.00015 0.00000 0.00000
6.00000 8.00000 0.40000 -0.01111 0.00062 -0.00010 0.00001 0.00000
9.00000 9.20000 0.33333 -0.00556 -0.00062 0.00007 0.00000 0.00000
12.00000 10.20000 0.30000 -0.01111 0.00046 0.00000 0.00000 0.00000
15.00000 11.10000 0.23333 -0.00556 0.00000 0.00000 0.00000 0.00000
18.00000 11.80000 0.18333 0.00000 0.00000 0.00000 0.00000 0.00000
24.00000 12.90000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
Valores de X e Y
3 6 9 12 15 18 24
6.2000 8.0000 9.2000 10.2000 11.1000 11.8000 12.9000

Polinomio interpolacion newton : 6.2+0.6*(x-3)-0.033333*(x-3).*(x-6)+0.0024691*(x-3).*(x-6).*(x-9)-0.00015432*(x-


3).*(x-6).*
(x-9).*(x-12)+3.4294e-06*(x-3).*(x-6).*(x-9).*(x-12).*(x-15)+2.9939e-07*(x-3).*(x-6).*(x-9).*(x-12).*(x-15).*(x-18)
X interp = 78

Punto fuera de rango. El resultado puede ser equivodado


Y(78)
Y(30139.5) KG

d)

Problema 02.

A) Polinomio interpolante grado 3 para v=0.2 (codigo)

%%NEWTON
function[yi,p,b]=pol_newton(x,y,xi)

n=length(x);
b=zeros(n);
b(:,1)=y(:);
%%TABLA DE DIFERENCIAS
for(j=2:n)
for(i=1:n-j+1)
b(i,j)=(b(i+1,j-1)-b(i,j-1))/(x(i+j-1)-x(i));
end
end

%%CALCULAR DATO INTERPOLADO

xt=1;
yi=b(1,1);

for(j=1:n-1)
xt=xt.*(xi-x(j));
yi=yi+b(1,j+i)*xt;
end
%%construir polinomio

p=num2str(b(1,1));
xx=x*-1;

for j=2:n
signo='';
if b(1,j)>=0
signo='+';
end
xt='';
for i=1:j-1
signo2='';
if(xx(i)>=0)
signo2='+';
end

xt=strcat(xt,'*(x',signo2,num2str(xx(i)),')');
end
p=strcat(p,signo,num2str(b(i,j)),xt);
end
RESOLVIENDO EN VENTANA DE COMANDOS

//Usamos en x (volumen ), y(presion) y VALOR (volumen a evaluar)


>> clear
>> format long
>> x=[0.1 0.1451 0.3 0.45492];
>> y=[650 500 250 150];
>> VALOR=0.2;
//y2=(valor evaluar), p=polinomio, b=tabla de diferencias divididas
>> [yi,p,b]=pol_newton(x,y,VALOR)
y2 = 380.42916
p = 650-3325.9424*(x-0.1)+8559.9893*(x-0.1)*(x-0.1451)-1531.1089*(x-0.1)*(x-0.1451)*(x-0.3)
b=

6.500000000000000e+02 -3.325942350332594e+03 8.559989350113585e+03 -1.531089254504268e+04


5.000000000000000e+02 -1.613944480309877e+03 3.125847368027038e+03 0.000000000000000e+00
2.500000000000000e+02 -6.454944487477408e+02 0.000000000000000e+00 0.000000000000000e+00
1.500000000000000e+02 0.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00

b)Hallar el error porcentual en a) para v=0.2 con todos los datos

//usando 5 valores
>> x1=[0.1 0.1451 0.3 0.45492 0.5];
>> y1=[650 500 250 150 100];
>> VALOR=0.2;
>> yi=pol_newton(x,y,VALOR)
yi = 372.8057865060926
//siendo el error porcentual
yi = 372.8057865060926
>> y2=380.42916;
>> ERRORPORCENTUAL=(y2-yi)/y2
ERRORPORCENTUAL = 2.003887791857864e-02

c)Usando el código

%%LAGRANGE
function[yi,polinomio]=LAGRANGE(xs,ys,x)
n=length(xs);
if(length(ys)~=n)
error('NO ES MISMA LONGUITUD');
end;
yi=0;
polinomio='0';
for(i=1:n)
producto=ys(i);
termino=num2str(ys(i));
for j=1:n
if i~=j
producto=producto*(x-xs(j))/(xs(i)-xs(j));
termino=strcat(termino,'*(x-',num2str(xs(j)),')/(',num2str(xs(i)),'-',num2str(xs(j)),')');
end
end
yi=yi+producto;
polinomio=strcat(polinomio,'+',termino);
end
endfunction
Obtenenmos:

(VENTANA DE COMANDOS)
>> clear
>> format long
>> x=[0.1 0.1451 0.3 0.45492];
>> y=[650 500 250 150];
//VALOR A EVALUAR
>> VALOR=0.2;
//yi(valor evaluado)
>> [yi,polinomio]=LAGRANGE(x,y,VALOR)
yi = 372.8057865060925
polinomio = 0+650*(x-0.1451)/(0.1-0.1451)*(x-0.3)/(0.1-0.3)*(x-0.45492)/(0.1-0.45492)+500*(x-0.1)/(0.1451-
0.1)*(x-0.3)/(0.1451-0.3)*(x-0.45492)/(0.1451-0.45492)+250*(x-0.1)/(0.3-0.1)*(x-0.1451)/(0.3-0.1
451)*(x-0.45492)/(0.3-0.45492)+150*(x-0.1)/(0.45492-0.1)*(x-0.1451)/(0.45492-0.1451)*(x-0.3)/(0.45492-0.3)

//ACOMODANDO EL POLINOMIO

Problema 03.
X 1 2 4
Y 5 m 17

(𝑥 − 4)(𝑥 − 2) (𝑥 − 1)(𝑥 − 4) (𝑥 − 1)(𝑥 − 2)


𝑃2 (𝑥) = (𝑏 + 𝑎) + (𝑎 + 𝑐) + (𝑏 + 𝑐)
(1 − 4)(1 − 2) (2 − 1)(2 − 4) (4 − 1)(4 − 2)

a)Calcular el valor de m,a,b y c.


b+a=5
a+c=m
b+c=17

utilizando solo dos puntos


X 1 4
y 5 17

Hallamos el m:
(𝑥 − 4) (𝑥 − 1)
𝑃1 (𝑥) = (5) + (17)
(1 − 4) (4 − 1)

Siendo x=2:

𝑃1 (2) = 9

Entonces:

𝑚≈9

X 1 2 4
Y 5 9 17

a=-1.5
b=6.5
c=10.5

b) Muestre el polinomio interpelante y calcule el valor aproximado para x=3

𝑥 2 − 6𝑥 + 8 𝑥 2 − 5𝑥 + 4 𝑥 2 − 3𝑥 + 2
𝑃2 (𝑥) = (5) + (9) + (17)
3 −2 6

𝑃2 (3) = 13
c)Usando el mismo método encontrar el polinomio interpelante y aproxime el valor de x para Y=10.

𝑥 2 − 6𝑥 + 8 𝑥 2 − 5𝑥 + 4 𝑥 2 − 3𝑥 + 2
𝑃2 (𝑥) = (5) + (9) + (17)
3 −2 6

𝑃2 (𝑥) = 4𝑥 + 1

𝑃2 (𝑥) = 10

Entonces:

9
𝑥=
4

Fecha: 27 de mayo de 2019

También podría gustarte