public static Matrix add(Matrix matrix1, Matrix matrix2) throws IllegalDimensionException {
        if (matrix1.getNcols() != matrix2.getNcols() || matrix1.getNrows() != matrix2.getNrows())
            throw new IllegalDimensionException("Two matrices should be the same dimension.");
        Matrix sumMatrix = new Matrix(matrix1.getNrows(), matrix1.getNcols());
        for (int i=0; i<matrix1.getNrows();i++) {
            for (int j=0;j<matrix1.getNcols();j++)
                sumMatrix.setValueAt(i, j, matrix1.getValueAt(i, j).add(matrix2.getValueAt(i, j)));

        }
        return sumMatrix;
    }