Beruflich Dokumente
Kultur Dokumente
Para los mtodos iterativos obtener la solucin de las incgnitas, cantidad de iteraciones y el error,
para los mtodos de factorizacin obtener las matrices de factorizacin.
1. Aplicar el Mtodo de Newton Raphson para resolver el sistema de ecuaciones no lineales, con
valores iniciales x=2, y=4, z=-1, para una tolerancia de 0.1%.
1 (, , ) = 2 + 37
2 (, , ) = 2 5
3 (, , ) = + + 3
function F=F(X)
x=X(1);
y=X(2);
z=X(3);
//Ejercicio 1
f1=(x^2)+y-37;
f2=x-(y^2)-5;
f3=x+y+z-3 ;
F=[f1;f2;f3];
endfunction
function J=J(X)
x=X(1);
y=X(2);
z=X(3);
//Ejercicio 1
df1x=2*x;
df1y=1;
df1z=0;
df2x=1;
df2y=-2*y;
df2z=0;
df3x=1;
df3y=1;
df3z=1;
clc
function newtonmultiple(X0, tol, N)
//x0 vector inicial
i=1;
eax(1)=100;
eay(1)=100;
eaz(1)=100;
X(:,1)=X0;
while (abs(eax(i))>tol) & (abs(eay(i))>tol) & (abs(eaz(i))>tol) &(i<=N)
X(:,i+1)=X(:,i)-J(X(:,i))\F(X(:,i));
eax(i+1)=abs((X(1,i+1)-X(1,i))/X(1,i+1)*100);
eay(i+1)=abs((X(2,i+1)-X(2,i))/X(2,i+1)*100);
eaz(i+1)=abs((X(3,i+1)-X(3,i))/X(3,i+1)*100);
i=i+1;
end
printf(' i \t x(i) y(i) z(i) Error x (i) Error y (i).Error z (i) \n');
for j=1:i;
printf('%2d \t %11.7f \t %11.7f \t %7.5f %12.5f %14.5f %16.5f \n',j-1,X(1,j),X(2,j),X(3,j),eax(j),eay(j),eaz(j));
end
endfunction
CONSOLA
newtonmultiple([2,4,-1],0.1,50)
2. Aplicar el Mtodo de Punto Fijo para resolver el sistema del punto anterior, evaluando slo uno de
los posibles despejes. Utilizar el criterio de convergencia para determinar si el despeje seleccionado
lleva a solucin.
CONSOLA
pfijom([2,4,-1],0.1, 50)
function g=Gm(X)
// Funcin para el mtodo de punto
// fijo multivariado con desplazamientos simultneos
x=X(1);
y=X(2);
Z=X(3);
//Ejercicio 1
g(1) = sqrt(37-y);
g(2) = sqrt(x-5);
g(3) = 3-x-y;
endfunction
clc
function pfijom(x0, tol, maxiter)
//Funcin para solucionar sistemas de ecuaciones no lineales
//por Punto fijo multivariado
i=1;
eax(1)=100;
eay(1)=100;
eaz(1)=100;
X(:,1)=x0;
while ((abs(eax(i))>tol) | (abs(eay(i))>tol) | (abs(eaz(i))>tol))&(i<= maxiter)
X(:,i+1) = Gm(X(:,i));
eax(i+1)=abs((X(1,i+1)-X(1,i))/X(1,i+1)*100);
eay(i+1)=abs((X(2,i+1)-X(2,i))/X(2,i+1)*100);
eaz(i+1)=abs((X(3,i+1)-X(3,i))/X(3,i+1)*100);
i=i+1;
end
if i>=maxiter then
disp('No converge')
else
printf(' i \t x(i) y(i) z(i) Error x (i) Error y (i) Error z (i) \n');
for j=1:i;
printf('%2d \t %11.7f \t %11.7f \t %7.5f %12.5f %16.5f %19.5f\n',j-1,X(1,j),X(2,j),X(3,j),eax(j),eay(j),eaz(j));
end
end
endfunction
3. Aplicar el mtodo de Gauss- seidel con tolerancia 0.0001 y comparar los resultados con los
obtenidos por medio del mtodo LU.
Gauss Seidel
D=diag(diag(A));
U=triu(A)-D;
L=tril(A)-D;
M=-inv(D+L)*U;
N=inv(D+L)*b;
cont=1;
xant=x0;
xsig=M*xant+N;
while norm(xsig-xant)>error_max
cont=cont+1;
xant=xsig;
xsig=M*xant+N;
end
sol=xsig;
niteraciones=cont;
er=norm(xsig-xant);
endfunction
CONSOLA
Recordar que en la diagonal no puede haber ceros
--> A=[-12 1 -1;-2 -4 2 ; 1 2 2]
A =
-12. 1. -1.
-2. -4. 2.
1. 2. 2.
20.
10.
25.
0.
0.
0.
--> gauss_seidel_matriz(A,b,x0,0.0001 )
ans =
-2.1999931
3.5999775
10.000019
---------------------------------------
METODO LU
-12. 1. -1.
-2. -4. 2.
1. 2. 2.
20.
10.
25.
--> [L,U]=lu(A);
--> x=U\(L\b)
x =
-2.2
3.6
10.
4. Aplicar la factorizacin de Cholesky y LU. Comparar los mtodos, cul recomendara usted?
Cholesky
--> A=[3 2 1 ; 2 3 2 ; 1 2 3]
A =
3. 2. 1.
2. 3. 2.
1. 2. 3.
--> b=[1;0;0]
b =
1.
0.
0.
--> T=chol(A);
--> X=T\(T'\b)
X =
0.625
-0.5
0.125
Factorizacin LU
--> A=[3 2 1 ; 2 3 2 ; 1 2 3]
A =
3. 2. 1.
2. 3. 2.
1. 2. 3.
--> b=[1;0;0]
b =
1.
0.
0.
--> [L,U]=lu(A);
--> x=U\(L\b)
x =
0.625
-0.5
0.125
5. Determinar los valores de las corrientes i1, i2, i3, aplicando el mtodo de Gauss-Seidel y el mtodo de
Jacobi con tolerancia 0.0001. Comparar las soluciones obtenidas con cada mtodo.
10. 8. 0.
0. -8. 5.
1. -1. -1.
--> b=[180;-50;0]
b =
180.
-50.
0.
0.
0.
0.
--> gauss_seidel_matriz(A,b,x0,0.0001)
ans =
11.411731
8.2352797
3.1764517
Jacobi
--> jacobi_matriz(A,b,x0,0.0001)
ans =
11.411783
8.2353478
3.1765507
6. Aplicar el mtodo de Jacobi con tolerancia 0.0001 y comparar los resultados con los obtenidos por
medio del mtodo de cholesky.
Jacobi
A =
4. 1. 1. 0. 1.
1. 3. 1. 1. 0.
1. 1. 5. -1. -1.
0. 1. -1. 4. 0.
1. 0. -1. 0. 4.
--> b=[6;6;6;6;6]
b =
6.
6.
6.
6.
6.
--> x0=[0;0;0;0;0]
x0 =
0.
0.
0.
0.
0.
--> jacobi_matriz(A,b,x0,0.0001)
ans =
0.4516097
0.7096907
1.677386
1.7419091
1.806435
Cholesky
A =
4. 1. 1. 0. 1.
1. 3. 1. 1. 0.
1. 1. 5. -1. -1.
0. 1. -1. 4. 0.
1. 0. -1. 0. 4.
--> T=chol(A);
--> X=T\(T'\b)
X =
0.4516129
0.7096774
1.6774194
1.7419355
1.8064516
Gradiente
A =
4. 1. -1. 1.
1. 4. -1. -1.
-1. -1. 5. 1.
1. -1. 1. 3.
--> b=[-2;-1;0;1]
b =
-2.
-1.
0.
1.
--> x=[0;0;0;0]
x =
0.
0.
0.
0.
--> metodo_gradiente(A,b,x,0.0001)
ans =
-0.7533777
0.0410428
-0.2807803
0.691709
Gradiente Conjugado
A =
4. 1. -1. 1.
1. 4. -1. -1.
-1. -1. 5. 1.
1. -1. 1. 3.
--> b=[-2;-1;0;1]
b =
-2.
-1.
0.
1.
--> x0=[0;0;0;0]
x0 =
0.
0.
0.
0.
ans =
-0.7534247
0.0410959
-0.2808219
0.6917808