You are on page 1of 1

%METODO DE GAUSS SEIDEL

clc; clear;
n=12;
opcion=1;
while n>10 || n<1
fprintf('\n RESOLUCION DE UN SISTEMA DE ECUACIONES \n')
n=input('Ingrese el orden del sistema: ');
%columna=input('Ingrese el numero de columnas: ');
end
for f=1:n
for c=1:n
fprintf('Ingrese el coeficiente (%d,%d)',f,c)
A(f,c)=input(' :');
end
fprintf('Ingrese el resultado de la ecuacion %d',f)
A(f,c+1)=input(' :');

end
A
%CONTROL DE UN ELEMENTO =0
%CONTADOR DE CAMBIO DE FILAS
%RIMER REORDENAMIENTO DE FILAS A LA MATRIZ A
for i=1:n

mayor=A(i,i);
if mayor<0 %valor absoluto
mayor=-1*mayor;
end
for j=i:n-1
if A(j+1,i)<0 %valor absoluto
aux=-1*A(j+1,i);
else
aux=A(j+1,i);
end

if mayor <aux
mayor =A(j+1,i); %comparacion de la posicion con mayor valor
end
end

for k=i:n-1
if mayor==A(k+1,i) % buscar mayor
if A(k,i+1)~=0 %control de elementomo de la diagonal =0

for j2=1:n
ayuda2=A(i,j2);
A(i,j2)=A(k+1,j2);
A(k+1,j2)=ayuda2;
end
end
end
A
end
end

You might also like