一: 矩阵的加法与减法
规则:矩阵的加法与减法要求两个矩阵的行列完全相等,方可以完成两个矩阵的之间的运算。
举例说明如下
二:矩阵的乘法
规则:矩阵的乘法要求两个矩阵符合A(mx k), B( k x n)即矩阵A的列数与矩阵B的行数相等,否
则无法完成矩阵运算。举例说明如下:
Java代码如下:
package pet.shop; public class BasicMatrixMath { public final static int OPERATION_ADD = 1; public final static int OPERATION_SUB = 2; public final static int OPERATION_MUL = 4; /** * To be able to add two matrices, they must be of the same size * @param matrixa * @param matrixb */ public int[][] add(int[][] matrixa, int[][] matrixb) { if(legalOperation(matrixa, matrixb, OPERATION_ADD)) { for(int i=0; i