@@ -40,21 +40,51 @@ public void updatePosition(Chromosome globalBest) {
4040 }
4141 }
4242
43- public double [][] sumMatrix (double [][] a , double [][] b ){
43+ public static double [][] sumMatrix (double [][] a , double [][] b ){
4444 if (a .length == b .length && a [0 ].length == b [0 ].length ){
4545 double [][] c = new double [a .length ][a [0 ].length ];
46-
4746 for (int i = 0 ; i < a .length ; i ++) {
4847 for (int j = 0 ; j < a [0 ].length ;j ++) {
4948 c [i ][j ] = a [i ][j ] +b [i ][j ];
5049 }
5150 }
5251 return c ;
5352 }
54-
53+
5554 System .out .println ("Matrix error" );
5655 return null ;
5756
57+ }
58+
59+ public static double [][] subtractionMatrix (double [][] a , double [][] b ){
60+ if (a .length == b .length && a [0 ].length == b [0 ].length ){
61+ double [][] c = new double [a .length ][a [0 ].length ];
62+ for (int i = 0 ; i < a .length ; i ++) {
63+ for (int j = 0 ; j < a [0 ].length ;j ++) {
64+ c [i ][j ] = a [i ][j ] - b [i ][j ];
65+ }
66+ }
67+ return c ;
68+ }
69+
70+ System .out .println ("Matrix error" );
71+ return null ;
72+
73+ }
74+
75+ public static double [][] multiplicationMatrix (double [][] a , double [][] b ){
76+ if (a .length == b .length && a [0 ].length == b [0 ].length ){
77+ double [][] c = new double [a .length ][a [0 ].length ];
78+ for (int i = 0 ; i < a .length ; i ++) {
79+ for (int j = 0 ; j < a [0 ].length ;j ++) {
80+ c [i ][j ] = a [i ][j ] * b [i ][j ];
81+ }
82+ }
83+ return c ;
84+ }
85+
86+ System .out .println ("Matrix error" );
87+ return null ;
5888
5989 }
6090
0 commit comments