package info.kalendra.matrixOps; import info.kalendra.matrix.Matrix; import java.security.InvalidParameterException; public class MatrixMultiplyMatrixMatrix { public Matrix multiply(Matrix x, Matrix y, Matrix z){ //check dimensions if(x.getDimensionCols() != y.getDimensionRows()){ throw new InvalidParameterException("Dimensions don't match"); } //set the dimensions of z z.setDimensions(x.getDimensionRows(), y.getDimensionCols()); //push the data into z double temp1; double temp2; for(int i = 0; i < x.getDimensionRows(); i++){ for(int j =0; j < y.getDimensionCols(); j++){ for(int k = 0; k < x.getDimensionCols(); k++){ temp1 = z.getValue(i, j); temp2 = x.getValue(i, k) * y.getValue(k, j); z.setValue(i, j, temp1 + temp2); } } } return z; } }