/** * Returns an estimate of the solution to the linear system A · x = b. * * @param a the linear operator A of the system * @param b the right-hand side vector * @return a new vector containing the solution * @throws NullArgumentException if one of the parameters is {@code null} * @throws NonSquareOperatorException if {@code a} is not square * @throws DimensionMismatchException if {@code b} has dimensions inconsistent with {@code a} * @throws MaxCountExceededException at exhaustion of the iteration count, unless a custom {@link * org.apache.commons.math3.util.Incrementor.MaxCountExceededCallback callback} has been set * at construction of the {@link IterationManager} */ public RealVector solve(final RealLinearOperator a, final RealVector b) throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException, MaxCountExceededException { MathUtils.checkNotNull(a); final RealVector x = new ArrayRealVector(a.getColumnDimension()); x.set(0.); return solveInPlace(a, b, x); }
/** * Performs all dimension checks on the parameters of {@link #solve(RealLinearOperator, * RealVector, RealVector) solve} and {@link #solveInPlace(RealLinearOperator, RealVector, * RealVector) solveInPlace}, and throws an exception if one of the checks fails. * * @param a the linear operator A of the system * @param b the right-hand side vector * @param x0 the initial guess of the solution * @throws NullArgumentException if one of the parameters is {@code null} * @throws NonSquareOperatorException if {@code a} is not square * @throws DimensionMismatchException if {@code b} or {@code x0} have dimensions inconsistent with * {@code a} */ protected static void checkParameters( final RealLinearOperator a, final RealVector b, final RealVector x0) throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException { MathUtils.checkNotNull(a); MathUtils.checkNotNull(b); MathUtils.checkNotNull(x0); if (a.getRowDimension() != a.getColumnDimension()) { throw new NonSquareOperatorException(a.getRowDimension(), a.getColumnDimension()); } if (b.getDimension() != a.getRowDimension()) { throw new DimensionMismatchException(b.getDimension(), a.getRowDimension()); } if (x0.getDimension() != a.getColumnDimension()) { throw new DimensionMismatchException(x0.getDimension(), a.getColumnDimension()); } }