matlab-metodo de jacobi/gauss seidel
Publicado por radio (9 intervenciones) el 02/01/2014 21:17:56
Tengo que solucionar el sistema de ecuaciones : KX=R con este método y el de Gauss Siedel con un error menor que 0,0001 por separado. Nos dieron los archivos del editor pero no funcionan...
Las matrices son:
K=[0.3 -0.1189 -0.0684 -0.1011 0 0;-0.189 0.4 -0.2111 -0.0059 0 0;-0.0684 -0.2111 0.7 -0.2378 -0.0059 -0.1011; -0.1011 -0.0059 -0.2378 0.74 -0.2111 -0.0684;0 0 -0.0059 -0.2111 0.43 -0.1189;0 0 -0.1011 -0.0684 -0.1189 0.34]
R=[40;0;0;50;0;35]
En archivo para el método de Jacobi dice:
function [solucion,num_iteraciones]=metodo_jacobi(A,B,punto_inicial,error)
cont_iteraciones=0;
s=size(A);
num_ecuaciones=s(1);
for k=1:num_ecuaciones
B(k)=B(k)/A(k,k);
A(k,:)=A(k,:)/A(k,k);
A(k,k)=0;
end
M=-A;
x_ant=punto_inicial';
x_sig=M*x_ant+B';
deltax_n=x_sig-x_ant;
while norm(deltax_n,inf) > error
x_sig=M*x_ant+B';
deltax_n=x_sig-x_ant;
x_ant=x_sig;
cont_iteraciones=cont_iteraciones+1;
end
solucion=x_sig;
num_iteraciones=cont_iteraciones;
El archivo para el método de Gauss Seidel dice:
function [sol,niteraciones,error]=metodo_gauss_seidel(A,B,x0,cotaerror)
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,inf)>cotaerror
cont=cont+1;
xant=xsig;
xsig=M*xant+N;
end
sol=xsig;
niteraciones=cont;
error=norm(xsig-xant,inf);
Si lo hago por Gauss me da la siguiente matriz de resultados:
1.0000 0 0 0 0 0 543.5471
0 1.0000 0 0 0 0 469.7630
0 0 1.0000 0 0 0 392.3194
0 0 0 1.0000 0 0 399.3537
0 0 0 0 1.0000 0 314.8165
0 0 0 0 0 1.0000 410.0322
Las matrices son:
K=[0.3 -0.1189 -0.0684 -0.1011 0 0;-0.189 0.4 -0.2111 -0.0059 0 0;-0.0684 -0.2111 0.7 -0.2378 -0.0059 -0.1011; -0.1011 -0.0059 -0.2378 0.74 -0.2111 -0.0684;0 0 -0.0059 -0.2111 0.43 -0.1189;0 0 -0.1011 -0.0684 -0.1189 0.34]
R=[40;0;0;50;0;35]
En archivo para el método de Jacobi dice:
function [solucion,num_iteraciones]=metodo_jacobi(A,B,punto_inicial,error)
cont_iteraciones=0;
s=size(A);
num_ecuaciones=s(1);
for k=1:num_ecuaciones
B(k)=B(k)/A(k,k);
A(k,:)=A(k,:)/A(k,k);
A(k,k)=0;
end
M=-A;
x_ant=punto_inicial';
x_sig=M*x_ant+B';
deltax_n=x_sig-x_ant;
while norm(deltax_n,inf) > error
x_sig=M*x_ant+B';
deltax_n=x_sig-x_ant;
x_ant=x_sig;
cont_iteraciones=cont_iteraciones+1;
end
solucion=x_sig;
num_iteraciones=cont_iteraciones;
El archivo para el método de Gauss Seidel dice:
function [sol,niteraciones,error]=metodo_gauss_seidel(A,B,x0,cotaerror)
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,inf)>cotaerror
cont=cont+1;
xant=xsig;
xsig=M*xant+N;
end
sol=xsig;
niteraciones=cont;
error=norm(xsig-xant,inf);
Si lo hago por Gauss me da la siguiente matriz de resultados:
1.0000 0 0 0 0 0 543.5471
0 1.0000 0 0 0 0 469.7630
0 0 1.0000 0 0 0 392.3194
0 0 0 1.0000 0 0 399.3537
0 0 0 0 1.0000 0 314.8165
0 0 0 0 0 1.0000 410.0322
Valora esta pregunta


0