Está en la página 1de 7

UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN

FACULTAD DE INGENIERIA CIVIL, ARQUITECTURA Y


GEOTECNIA
ESCUELA PROFESIONAL DE INGENIERIA CIVIL

CÁLCULO NUMÉRICO
PRÁCTICA ENCARGADA n°4:
DIAGRAMAS Y CÓDIGOS
GAUSS JORDAN-JACOBBI-GAUSS SEIDEL
DOCENTE: Mg. Elder Joel Varas Pérez
Grupo 3
Integrantes:
-Angeline Nicoll Mamani Quenta 2021-129042
-Rusbell Adán Cruz Gallegos 2021-129023
-Klaus Ivanov Ramírez Apaza 2021-129060
-Marco Antonio Miranda Claros 2021-129014
-Luigui Jean Venegas Vilca 2021-129026

Tacna-2022
GAUSS-JORDAN
DIAGRAMA DE FLUJO
MÉTODO DE GAUSS JORDAN -CÓDIGO EN MATLAB

clc % limpia pantalla


clear % borra variables
disp('********************************************************')
disp(' MÉTODO DE GAUSS - JORDAN ')
disp('********************************************************')
A=input('Ingrese la matriz Aumentada: '); %Ingresa el sistema en forma matricial
[m,n]=size(A); % asigna a m el número de filas que tiene A y a n el número
% de columnas que tiene A
clc
disp("Matriz aumentada")
disp(A); % muestra en pantalla la forma matricial del sistema
x=zeros(1,m); %define las dimensiones del vector solución, inicialmente
%todos los elementos son ceros y que serán actulizados.

for i=1:m
aux=0;
for p=i:m %busca el pivote
if A(p,i)~=0
aux=1;
break
end
end
if aux==1
if p~=i % Si encuentra el pivote en una fila diferente intercambia filas
tem=A(i,:);
A(i,:)=A(p,:);
A(p,:)=tem;
end
for j=1:m % Eliminación de los elementos por encima y por debajo del
pivote
if i~=j
A(j,:)=A(j,:)-A(j,i)/A(i,i)*A(i,:);
end
end
else
disp('El sistema no tiene solución única')
break
end
end

disp("Matriz Digonal")
disp(A);
if aux==1
for i=1:m
x(i)=A(i,n)/A(i,i);
end
disp('La solución es:')
disp(x);
end
MÉTODO INICIO
ITERATIVO DE
JACOBI

function
jacobimetodo(
A,b,x,tol,m)

n=length(x)

for k=1:m

w=x

for i=1:n

s=A(i,1:i-1)*w(1:i-1)+A(i,i+1:n)*w(i+1:n)

x(i)=(b(i)-s)/A(i,i)

norm(w-
V x,inf)<tol

la solucion del sistema en

la iteracion

i=1:n

i,x(i)

FINAL
METODO JACOBI

function jacobimetodo(A,b,x,tol,m)n=length(x);
for k=1:m
w=x;
for i=1:n
s=A(i,1:i-1)*w(1:i-1)+A(i,i+1:n)*w(i+1:n);
x(i)=(b(i)-s)/A(i,i);
end
if norm(w-x,inf)<tol
return
end
fprintf('\n la solucion del sistema en la
iteracion %4.0f\n',k)
for i=1:n
fprintf(' x(%1.0f)=%6.8f\n',i,x(i))
end
end
MÉTODO GAUSS SEIDEL

clear all
clc
disp ('******************************************************************');
disp ('***************** MÉTODO DE GAUSS - SEIDEL ***********************');
disp ('******************************************************************');
A=input('ingresar la matriz con los coeficientes del sistema: ');
b=input ('Ingresa el vector fila con los terminos independientes: ');
XO=input('Ingrese el vector fila con los valores iniciales para las iteraciones: ');
TOL=input('Ingrese la tolerancia: ');
N=input('Ingrese el número maximo de iteraciones: ');
[m,n]=size(A);
b=b';
XO=XO';
n=length(XO);
K=1
while K<=N
v=XO;
for i=1:n
suma=A(i,1:i-1)*XO(1:i-1)+A(i,i+1:n)*XO(i+1:n);
XO(i)=(b(i)-suma)/A(i,i);
end
norma=norm(v-XO);
if norma<=TOL
fprintf('\n La solución en la iteracion:%4.0f es:\n',K);
for i=1:n
fprintf(' XO(%1i)=%6.8f\n',i,XO(i))
end
fprintf(' norma=%8.6e\n',norma)
w=2;
break
else
fprintf('\nPara la iteración: %4.0f\n',K)
for i=1:n
fprintf(' XO(%1i)=%6.8f\n',i,XO(i))
end
fprintf(' norma=%8.6e\n', norma)
w=1;
end
K=K+1;
end
if w==1
fprintf('\n El método diverge en %2i Iteraciones \n', N)
fprintf('Intenta dar un mayor número de iteraciones')
end

También podría gustarte