Skip to content
ForCADDocumentation

solve Function

public pure function solve(A, B) result(X)

Solve the square dense system for one or more right-hand sides.

A matrix is classified as numerically symmetric when every compared pair satisfies the scale-invariant test

That path first attempts unpivoted Cholesky using the lower triangle. Before accepting its solution, the full input matrix is checked with the componentwise backward-residual bound

where is the model exponent of the largest entry. Scaling by a radix power is exact. Cholesky and LU both solve , with , so their pivot decisions and arithmetic do not depend on the physical units of the system.

If Cholesky encounters a nonpositive pivot, the residual check fails, or the symmetry test fails, LU factorization with partial pivoting solves the normalized general system. Shape mismatch, an exactly zero LU pivot, a nonfinite pivot, or a nonfinite solution returns X(0,0). A small nonzero normalized pivot is accepted; its magnitude alone does not prove singularity.

The routine is allocation-based and intended for small or medium dense systems. Work is , and dense factor and solution storage is allocated internally. The routine does not estimate a condition number or perform iterative refinement. All entries of A and B must be finite.

Reference implementations:

  • LAPACK DPOSV, symmetric positive-definite solution by Cholesky factorization: Netlib LAPACK.
  • LAPACK DGESV, general solution by LU factorization with partial pivoting: Netlib LAPACK.

Arguments

Type IntentOptional Attributes Name
real(kind=rk), intent(in), contiguous :: A(:,:)

Square coefficient matrix, shape [n,n].

real(kind=rk), intent(in), contiguous :: B(:,:)

Right-hand sides, shape [n,nrhs].

Return Value real(kind=rk), allocatable, (:,:)