java矩阵乘法实现
package com. zhiyou100. test;
public class MatrizMultiple {
public static void main ( String[ ] args) {
int a[ ] [ ] = { { 5 , 7 , 8 , 2 } ,
{ - 2 , 4 , 1 , 2 } ,
{ 1 , 2 , 3 , 4 } } ;
int b[ ] [ ] = { { 4 , - 2 , 3 , 3 , 9 } ,
{ 4 , 3 , 8 , - 1 , 2 } ,
{ 2 , 3 , 5 , 2 , 7 } ,
{ 1 , 0 , 6 , 3 , 4 }
} ;
int c[ ] [ ] = new int [ 3 ] [ 5 ] ;
for ( int i= 0 ; i< 3 ; i++ )
for ( int j= 0 ; j< 5 ; j++ )
for ( int k= 0 ; k< 4 ; k++ )
c[ i] [ j] = c[ i] [ j] + a[ i] [ k] * b[ k] [ j] ;
for ( int i= 0 ; i< 3 ; i++ ) {
for ( int j= 0 ; j< 5 ; j++ )
System. out. print ( c[ i] [ j] + " " ) ;
System. out. println ( ) ;
}
}
}
package com. zhiyou100. test;
public class MatrizMultiple {
public static void main ( String[ ] args) {
int a[ ] [ ] = { { 1 , 3 , 5 } ,
{ - 3 , 6 , 0 } ,
{ 13 , - 5 , 7 } ,
{ - 2 , 19 , 25 } } ;
int b[ ] [ ] = { { 0 , - 1 , - 2 } ,
{ 7 , - 1 , 6 } ,
{ - 6 , 13 , 2 } ,
{ 12 , - 8 , - 13 }
} ;
int c[ ] [ ] = new int [ 4 ] [ 3 ] ;
for ( int i= 0 ; i< 4 ; i++ )
for ( int j= 0 ; j< 3 ; j++ )
c[ i] [ j] = c[ i] [ j] + a[ i] [ j] + b[ i] [ j] ;
for ( int i= 0 ; i< 4 ; i++ ) {
for ( int j= 0 ; j< 3 ; j++ )
System. out. print ( c[ i] [ j] + " " ) ;
System. out. println ( ) ;
}
}
}
```! [ 在这里插入图片描述] ( https: / / img- blog. csdnimg. cn/ 20200407160638786. png)
```java
package com. zhiyou100. test;
public class MatrizMultiple {
public static void main ( String[ ] args) {
int a[ ] [ ] = { { 1 , 3 , 5 } ,
{ - 3 , 6 , 0 } ,
{ 13 , - 5 , 7 } ,
{ - 2 , 19 , 25 } } ;
int b[ ] [ ] = { { 0 , - 1 , - 2 } ,
{ 7 , - 1 , 6 } ,
{ - 6 , 13 , 2 } ,
{ 12 , - 8 , - 13 }
} ;
int c[ ] [ ] = new int [ 4 ] [ 3 ] ;
for ( int i= 0 ; i< 4 ; i++ )
for ( int j= 0 ; j< 3 ; j++ )
c[ i] [ j] = c[ i] [ j] + a[ i] [ j] - b[ i] [ j] ;
for ( int i= 0 ; i< 4 ; i++ ) {
for ( int j= 0 ; j< 3 ; j++ )
System. out. print ( c[ i] [ j] + " " ) ;
System. out. println ( ) ;
}
}
}