diff --git a/src/main/java/com/mattrixwv/matrix/DoubleMatrix.java b/src/main/java/com/mattrixwv/matrix/DoubleMatrix.java index bc8d4ee..519443f 100644 --- a/src/main/java/com/mattrixwv/matrix/DoubleMatrix.java +++ b/src/main/java/com/mattrixwv/matrix/DoubleMatrix.java @@ -1,7 +1,7 @@ //Matrix/src/main/java/com/mattrixwv/matrix/DoubleMatrix.java //Mattrixwv // Created: 02-07-22 -//Modified: 02-07-22 +//Modified: 02-08-22 package com.mattrixwv.matrix; @@ -172,7 +172,12 @@ public class DoubleMatrix{ return new DoubleMatrix(newRow); } public int getNumRows(){ - return grid.length; + if(grid == null){ + return 0; + } + else{ + return grid.length; + } } public DoubleMatrix getCol(int col){ //Make sure the column number is valid @@ -698,7 +703,7 @@ public class DoubleMatrix{ double[][] newGrid = new double[getNumRows()][getNumCols()]; //If the grid is 1x1 return the grid if(getNumRows() == 1){ - newGrid[0][0] = grid[0][0]; + newGrid[0][0] = 1; } //Use the formula to find the cofactor matrix else{ @@ -743,7 +748,7 @@ public class DoubleMatrix{ DoubleMatrix rightMatrix = (DoubleMatrix)rightSide; //Make sure they have the same number of elements - if(grid.length != rightMatrix.grid.length){ + if(getNumRows() != rightMatrix.getNumRows()){ return false; } else if(getNumCols() != rightMatrix.getNumCols()){ @@ -751,8 +756,8 @@ public class DoubleMatrix{ } //Check every element - for(int row = 0;row < grid.length;++row){ - for(int col = 0;col < grid[0].length;++col){ + for(int row = 0;row < getNumRows();++row){ + for(int col = 0;col < getNumCols();++col){ if(Math.abs(grid[row][col] - rightMatrix.grid[row][col]) > delta){ return false; } @@ -785,10 +790,10 @@ public class DoubleMatrix{ @Override public String toString(){ StringJoiner matrix = new StringJoiner("\n"); - for(int rowCnt = 0;rowCnt < grid.length;++rowCnt){ + for(int rowCnt = 0;rowCnt < getNumRows();++rowCnt){ StringJoiner row = new StringJoiner(",", "[", "]"); - for(int colCnt = 0;colCnt < grid[0].length;++colCnt){ + for(int colCnt = 0;colCnt < getNumCols();++colCnt){ row.add(Double.toString(grid[rowCnt][colCnt])); }