*
* @author Johana Ruales
*/
public class Matriz {
public int numeroFilas;
public int numeroColumnas;
public int [][]matriz;
public Matriz(){//crea una matriz sin dimensiones
}
//constructor con parametros
//nF es el numero de filas de la matriz
//nC es el numero de columnas de la matriz
public Matriz(int nF, int nC){
numeroFilas=nF;
numeroColumnas=nC;
matriz=new int[numeroFilas][numeroColumnas];
for(int i=0; i
}
//Transpuesta de la matriz
//el numero de filas se cambia al numero de columnas
public Matriz Transpuesta(){
Matriz resultado;
resultado=new Matriz(this.numeroColumnas,this.numeroFilas);
for(int i=0; i
return resultado;
}
//multiplicacion de matrices
//el numero de filas de la primera tiene que ser igual al numero de columnas
//de la otra matriz
public Matriz Multiplicacion(Matriz b){
Matriz resultado;
if(b.numeroFilas==this.numeroColumnas){
resultado=new Matriz(this.numeroFilas, b.numeroColumnas);
for(int i=0; i
}
}
return resultado;
}
else
System.out.println("ERROR EN DIMENSIONES DE LAS MATRICES");
resultado=null;
return resultado;
}
//metodo para imprimir las matrices
//devulve el objeto matriz como texto
public String toString(){
String aux="\n[\n";
for(int i=0; i
}
aux+="\n";
}
aux+="]";
return aux;
}
}
PRUEBA MATRIZ
/**
*
* @author Johana Ruales
*/
public class PruebaMatriz {
public static void main(String args[]){
Matriz a=new Matriz(1,5);
a.matriz[0][0]=1; a.matriz[0][1]=-1; a.matriz[0][2]=0; a.matriz[0][3]=1; a.matriz[0][4]=1;
//System.out.println("LA MATRIZ A ES: "+a.toString());
Matriz b=new Matriz (5,3);
b.matriz[0][0]=6; b.matriz[0][1]=-2; b.matriz[0][2]=5;
b.matriz[1][0]=4; b.matriz[1][1]=2; b.matriz[1][2]=-1;
b.matriz[2][0]=0; b.matriz[2][1]=1; b.matriz[2][2]=1;
b.matriz[3][0]=-2; b.matriz[3][1]=-2; b.matriz[3][2]=0;
b.matriz[4][0]=1; b.matriz[4][1]=0; b.matriz[4][2]=-1;
//System.out.println("LA MATRIZ B ES: "+b.toString());
Matriz c=new Matriz (2,3);
c.matriz[0][0]=2; c.matriz[0][1]=2; c.matriz[0][2]=1;
c.matriz[1][0]=3; c.matriz[1][1]=-1; c.matriz[1][2]=0;
//System.out.println("LA MATRIZ C ES: "+c.toString());
Matriz e=new Matriz(3,3);
e.matriz[0][0]=-1; e.matriz[0][1]=0; e.matriz[0][2]=-1;
e.matriz[1][0]=1; e.matriz[1][1]=0; e.matriz[1][2]=1;
e.matriz[2][0]=-1; e.matriz[2][1]=1; e.matriz[2][2]=-1;
//System.out.println("LA MATRIZ E ES: "+e.toString());
System.out.println("EL RESULTADO UNO ES: ");
Matriz u;
u=c.Multiplicacion(e);
System.out.println("EL RESULTADO DE MULTIPLICAR CE ES: "+u.toString());
Matriz o;
o=b.Transpuesta();
System.out.println("\nLA MATRIZ TRANSPUESTA DE B ES: "+o.toString());
Matriz ñ;
ñ=u.Multiplicacion(o);
System.out.println("\nEL RESULTADO CEBt ES: "+ñ.toString());
System.out.println("\n\nEL RESULTADO DOS ES: ");
Matriz d;
d=a.Multiplicacion(b);
System.out.println("EL RESULTADO DE MULTIPLICAR AB: "+d.toString());
Matriz p;
p=d.Multiplicacion(e);
System.out.println("\nEL RESULTADO DE MULTIPLICAR ABE ES: "+p.toString());
System.out.println("\n\nEL RESULTADO TRES ES: ");
Matriz w;
w=b.Transpuesta();
System.out.println("LA MATRIZ TRANSPUESTA DE B ES: "+w.toString());
Matriz x;
x=a.Transpuesta();
System.out.println("\nLA MATRIZ TRANSPUESTA DE A ES: "+x.toString());
Matriz t;
t=e.Multiplicacion(w);
System.out.println("\nLA MULTIPLICACION DE EBt ES: "+t.toString());
Matriz y;
y=t.Multiplicacion(x);
System.out.println("\nEL RESULTADO DE MULTIPLICAR EBtAt ES: "+y.toString());
}
}
RESULTADOS
EL RESULTADO UNO ES:
EL RESULTADO DE MULTIPLICAR CE ES:
[
-1 1 -1
-4 0 -4
]
LA MATRIZ TRANSPUESTA DE B ES:
[
6 4 0 -2 1
-2 2 1 -2 0
5 -1 1 0 -1
]
EL RESULTADO CEBt ES:
[
-13 -1 0 0 0
-44 -12 -4 8 0
]
EL RESULTADO DOS ES:
EL RESULTADO DE MULTIPLICAR AB:
[
1 -6 5
]
EL RESULTADO DE MULTIPLICAR ABE ES:
[
-12 5 -12
]
EL RESULTADO TRES ES:
LA MATRIZ TRANSPUESTA DE B ES:
[
6 4 0 -2 1
-2 2 1 -2 0
5 -1 1 0 -1
]
LA MATRIZ TRANSPUESTA DE A ES:
[
1
-1
0
1
1
]
LA MULTIPLICACION DE EBt ES:
[
-11 -3 -1 2 0
11 3 1 -2 0
-13 -1 0 0 0
]
EL RESULTADO DE MULTIPLICAR EBtAt ES:
[
-6
6
-12
]