Академический Документы
Профессиональный Документы
Культура Документы
Ejercicio 1:
POLINOMIO DE LAGRANGE
Encontrar el polinomio de grado 3 que cumple p(1)=1, p(2)=1, p(3)=2,
p(4)=6.
x=[1, 2, 3, 4]
y=[1; 1; 2; 6]
vander(x)
x= 1
y= 1
1
2
6
ans = 1
1
8
4
27
9
64 16
1
2
3
4
1
1
1
1
Ejercicio 2:
Diferencias divididas
A continuacin vamos a construir con Matlab la tabla de diferencias
divididas de una funcin en unos nodos x(0), x(1), ..., x(N-1), x(N). (Ref: Diez
lecciones de Clculo Numrico. J. M. Sanz Serna.) (Ref: Numerical methods
using Matlab. J. H. Mathews y K. D. Fink.)
Construiremos una tabla como la que se muestra, donde xN-1 es el nodo
x(N-1), xN-2 el nodo x(N-2), etc.
x0
x1
x2
.
.
.
xN
f[x0]
f[x1]
f[x2]
.
.
.
f[xN]
f[x0,x1]
f[x1,x2] f[x0,x1,x2]
.
.
.
.
.
.
.
.
.
f[xN-1,xN] f[xN-2,xN-1,xN] ... f[x0,...,xN]
M=NaN(N+1,N+2);
1.0000
1.0000
2.0000
6.0000
Ejercicio 3:
NaN
NaN
NaN
0
NaN
NaN
1.0000 0.5000
NaN
4.0000 1.5000 0.3333
Forma de Newton
Con las diferencias divididas calculadas podemos construir el polinomio de
interpolacin en la forma de Newton, donde xN-1 es el nodo x(N-1): P(x)
=f[x0] + f[x0,x1]*(x-x0) + f[x0,x1,x2]*(x-x0)*(x-x1) + ... + f[x0,x1,...,xN]*(xx0)*(x-x1)* ... *(x-xN-1) .
En primer lugar veremos como construir el polinomio q(x)=(x-x0)*(x-x1)* ...
*(x-xN) a partir de los valores x=[x0, x1, x2, ..., xN]. Usaremos un
acumulador de producto, que comenzar valiendo el polinomio constante
[1], y le iremos multiplicando los monomios (x-xj) que se expresan en forma
de vectores como [1, -xj].
q=[1];
for i=2:N+1
monomio=[1, -nodos(i-2+1)]
q=conv(q,monomio)
end
monomio = 1
q= 1
-1
-1
monomio = 1
q= 1
-3
monomio = 1
q= 1
-6
-2
-3
11
-6
monomio = 1
-1
q= 1
-1
newton = 0
monomio = 1
q= 1
-3
-2
-6
11
2.0000
-3
-6
2.1667
Ejercicio 4:
x=[0.97 1.12 2.92 3.00 3.33 3.97 6.10 8.39 8.56 9.44];
y=[2.58 0.43 0.06 5.74 7.44 8.07 6.37 2.51 1.44 0.52];
n=length(x); %nmero de pares de datos
%A=vander(x);
A=zeros(n); %lneas equivalentes a utilizar vander(x)
for j=1:n
A(:,j)=(x').^(n-j);
end
p=A\y'; %sistema de ecuaciones lineales, y' es vector columna
p=polyfit(x,y,n-1) %n-1 es el grado del polinomio
xx=linspace(0.97,9.44,50); %interpolacin
yy=polyval(p,xx);
hold on
plot(x,y,'o','markersize',4,'markerfacecolor','r')
plot(xx,yy,'b')
xlabel('x')
ylabel('y')
title('Interpolacin de Lagrange');
hold of
Corremos el script interpola-1 en la ventana de comandos, obtenemos un
aviso, los coeficientes del polinomio y la representacin grfica de los datos
y del polinomio que pasa por dichos puntos.
p = 1.0e+004 *
0.0000 -0.0003
3.9256 -1.1823
0.0057 -0.0595
0.3782 -1.4951
3.6430 -5.2142
Ejercicio 5:
Ejemplo 1:
xf(1)=input('Ingrese el valor inicial: ');
f2=subs(f,x,fx(2));
ea(1)=100;
i=1;
j=2;
while abs(ea(i))>=tol
xf(j+1)=(xf(j-1)*f2-xf(j)*f1)/(f2-f1); f1=f2; f2=subs(f,x,xf(j+1));
ea(i+1)=(xf(j+1)-xf(j))/xf(j+1)*100;
j=j+1;
i=i+1;
end
fprintf(' i
xf(i)
Error aprox (i) \n');
%fprintf('%2d\t%11.7f\t\n',0,x(1));
for k=2:j;
fprintf('%2d\t%11.7f\t%7.3f\n',k-1,xf(k),ea(k-1));
end
Ejercicio 4:
xai=input('Ingrese el intervalo inferior: ');
xbi=input('Ingrese el intervalo superior: ');
tol=input('Ingrese el porcentaje de error: ');
syms x;
f=input('Ingrese la funcin: ');
i=1;
f1=subs(f,x,xai);
f2=subs(f,x,xbi);
ea(i)=100;
if f1*f2 < 0
xa(i)=xai; f1=subs(f,x,xa(i));
xb(i)=xbi; f2=subs(f,x,xb(i));
xr(i)=(xa(i)+xb(i))/2; f3=subs(f,x,xr(i));
fprintf('It.
Xa
Xr
Xb
Error aprox \n');
fprintf('%2d \t %11.7f \t %11.7f \t %11.7f \n',i,xa(i),xr(i),xb(i));
while abs(ea(i)) >= tol,
if f1*f3<0
xa(i+1)=xa(i);f1=subs(f,x,xa(i+1));
xb(i+1)=xr(i);f2=subs(f,x,xb(i+1));
end
if f1*f3> 0
xa(i+1)=xr(i);f1=subs(f,x,xa(i+1));
xb(i+1)=xb(i);f2=subs(f,x,xb(i+1));
end
xr(i+1)=(xa(i+1)+xb(i+1))/2; f3=subs(f,x,xr(i+1));
ea(i+1)=abs((xr(i+1)-xr(i))/(xr(i+1))*100);
fprintf('%2d \t %11.7f \t %11.7f \t %11.7f \t %7.3f \n',...
i+1,xa(i+1),xr(i+1),xb(i+1),ea(i+1));
i=i+1;
end
else
fprintf('No existe una raz en ese intervalo');
end
Ejercicio 5:
Sea la funcin: x3 + 4x2 10 = 0 tiene una raz en [1, 2]
Puede despejarse en:
a. x = g1(x) = x x3 4x2 +10
b. x = g2(x) = (10 x3)
c. x = g3(x) = (10/(4 + x))
d. x = g4(x) = x (x3 + 4x2 10)/(3x2 + 8x)
(a)
(d)
(b)
(c)
1 1.5 1.5
1.5
1.5
2 -0.8751.3733333331.2869537
1.34839972
1.36526201467
3 6.732421875
4
1.3652300131.4025408
4
1.36737637
1.36523001303
-469.72001200
1
5 1.02754555E8
1.3454583
1.36495701
6
74
5
-1.084933870E2
1.3751702
1.36526474
4
52
8
7
1.3600941
1.36522559
1.277055591E7
92
4
2
1.3678469
1.36523057
8
67
5
-2.082712908E2
1.3638870
1.36522994
16
03
1
9 NaN
1.3659167
1.36523002
10
33
2
11
1.3648782
1.36523001
12
17
2
13
1.3654100
1.36523001
14
61
3
15
1.3651378
1.36523001
20
20
3
25
1.3652772
30
08
1.3652058
50
1.3652423
83
1.3652295
78
ASIGNATURA: Mtodos
Numricos
1.3652300
28
1.3652300
12
UNIVERSIDAD NACIONAL DE
SAN MARTN
CDIGO: 72313130
CICLO: V
MORALES-PER
2015