DiagonalMatrix extends AbstractRealMatrix implements Serializable { public DiagonalMatrix inverse() throws SingularMatrixException { return inverse(0); } DiagonalMatrix(final int dimension);  DiagonalMatrix(final double[] d);  DiagonalMatrix(final double[] d, final boolean copyArray); @Override RealMatrix createMatrix(final int rowDimension,
                                   final int columnDimension); @Override RealMatrix copy(); DiagonalMatrix add(final DiagonalMatrix m); DiagonalMatrix subtract(final DiagonalMatrix m); DiagonalMatrix multiply(final DiagonalMatrix m); @Override RealMatrix multiply(final RealMatrix m); @Override double[][] getData(); double[] getDataRef(); @Override double getEntry(final int row, final int column); @Override void setEntry(final int row, final int column, final double value); @Override void addToEntry(final int row,
                           final int column,
                           final double increment); @Override void multiplyEntry(final int row,
                              final int column,
                              final double factor); @Override int getRowDimension(); @Override int getColumnDimension(); @Override double[] operate(final double[] v); @Override double[] preMultiply(final double[] v); @Override RealVector preMultiply(final RealVector v); DiagonalMatrix inverse(); DiagonalMatrix inverse(double threshold); boolean isSingular(double threshold);  }
@Test(expected=SingularMatrixException.class) public void testInverseError() { final double[] data = { 1, 2, 0 }; final DiagonalMatrix diag = new DiagonalMatrix(data); diag.inverse(); }
@Test(expected=SingularMatrixException.class) public void testInverseError2() { final double[] data = { 1, 2, 1e-6 }; final DiagonalMatrix diag = new DiagonalMatrix(data); diag.inverse(1e-5); }
@Test public void testInverse() { final double[] data = { 1, 2, 3 }; final DiagonalMatrix m = new DiagonalMatrix(data); final DiagonalMatrix inverse = m.inverse(); final DiagonalMatrix result = m.multiply(inverse); TestUtils.assertEquals("DiagonalMatrix.inverse() returns wrong result", MatrixUtils.createRealIdentityMatrix(data.length), result, Math.ulp(1d)); }