Está en la página 1de 2

MULTIPLICACIN DE MATRICES for i=1:n

clc P(i)=i;
clear all for j=1:n
n=input('ingrese numero de filas para A'); tmp=sprintf('A(%d,%d)=',i,j);
p=input('ingrese numero de columnas para A(i,j)=input(tmp);
A'); end
q=input('ingrese numero de filas para B'); end
r=input('ingrese numero de columnas para s=1;
B'); for i=1:n-1
if(p~=q) if (A(P(i),i)==0)
error('Las matrices no se pueden r=1;
multiplicar') for k=i+1:n
end if (A(P(k),i)~=0)
for i=1:n a=P(i);
for j=1:p P(i)=P(k);
temp=sprintf('ingrese valor para P(k)=a;
posicion A(%d,%d):',i,j); r=0;
A(i,j)=input(temp); s=s*-1;
end break;
end end
for i=1:q end
for j=1:r if r==1
temp=sprintf('ingrese valor para error('la matriz no es linealmente
posicion B(%d,%d):',i,j); independiente')
B(i,j)=input(temp); end
end end
end for j=i+1:n
for i=1:n m=(A(P(j),i))/(A(P(i),i));
for j=1:r for k=i:n
C(i,j)=0; A(P(j),k)=A(P(j),k)-m*A(P(i),k);
for k=1:p end
C(i,j)=C(i,j)+A(i,k)*B(k,j); end
end end
end for i=1:n
end s=s*(A(P(i),i));
%respuesta end
tmp=sprintf('El determinante es %f',s);
DETERMINANTE DE UNA MATRIZ disp(tmp);
clc
clear all SISTEMA DE NXN GAUSS
n=input('ingrese el orden de la matriz='); clc
clear all if M(P(K),K)==0
n = input ('Ingrese el nmero de error('El sistema de ecuaciones no es
ecuaciones '); linealmente independiente');
for i =1:n end
P(i)=i; %vector de pivoteo end
for j =1:n+1
msj = sprintf('ingrese el elemento for K=n:-1:1
M(%d,%d)=',i,j); tmp=0;
M(i,j)= input (msj); for J=K+1:n
end tmp=tmp+X(J)*M(P(K),J);
end end
for K =1:n-1 X(K)=(M(P(K),n+1)-tmp)/M(P(K),K);
if M(P(K),K)==0 end
r=1; disp('La respuesta es');X
for I=K+1:n
if M(P(I),K)~=0
A=P(I);
P(I)=P(K);
P(K)=A;
r=0; %para saber que ha entrado
aqu
break;
end
end
if r==1
error('El sistema de ecuaciones no
es linealmente independiente');
end
end
for J =K+1:n
h = -(M(P(J),K)/M(P(K),K));
for I =K:n+1
M(P(J),I)=M(P(J),I)+h*M(P(K),I);
end
end
end
%antes de calcular la solucin debemos
verificar que
%todos los elementos de la diagonal son
distintos de cero
for K=1:n

También podría gustarte