Documentos de Académico
Documentos de Profesional
Documentos de Cultura
n=length(b);
for i=1:n
a(i,n+1)=b(i);
end
[nrow,ncol]=size(a);
for k=1:nrow
pivot=a(k,k);
il=k;
for l=k+1:nrow
if abs(a(l,k))<abs(pivot)
elseif abs(a(l,k)) >= abs(pivot)
pivot=a(l,k);
il=l;
end
end
if pivot ==0
disp('Matriz Singular')
else
for ll=1:ncol
temp=a(k,ll);
a(k,ll)=a(il,ll);
a(il,ll)=temp;
end
end
for j=1:ncol
c(k,j)=a(k,j)/pivot;
end
for i=1:nrow
if i==k
else
for j=1:ncol
c(i,j)=a(i,j)-a(i,k)*c(k,j)
end
end
end
% Ahora ponemos el resultado c() en a()
a=c;
for j=1:nrow
x(j)=a(j,ncol);
end
end
function[x,iter,incr]=Gauss_Seidel(A,b,x0,tol,maxiter)
n=length(b); % generar vector del tamaño de B
M=tril(A); % matriz triangular inferior
U=triu(A,1); % matriz triangular superior
iter=0; % inicio del contador
incr=tol+1; % inicio del error
x=zeros(n,1);% generacion de un vector de zeros de n filas y una columna
while iter<=maxiter && incr>tol % condiciones para seguir iterando
d=b-U*x0; %vector de terminos independientes
x(1)=d(1)/M(1,1); % primera ecuacion
for k =2:n
x(k,1)=(d(k)-M(k,1:k-1)*x(1:k-1,1))/M(k,k);% esttoy resolviendo como producto escalar
end
end