naginterfaces.library.correg.corrmat_nearest(g, errtol=0.0, maxits=0, maxit=0)[source]

corrmat_nearest computes the nearest correlation matrix, in the Frobenius norm, to a given square, input matrix.

For full information please refer to the NAG Library document for g02aa

gfloat, array-like, shape

, the initial matrix.

errtolfloat, optional

The termination tolerance for the Newton iteration. If , is used.

maxitsint, optional

specifies the maximum number of iterations used for the iterative scheme used to solve the linear algebraic equations at each Newton step.

If , is used.

maxitint, optional

Specifies the maximum number of Newton iterations.

If , is used.

xfloat, ndarray, shape

Contains the nearest correlation matrix.


The number of Newton steps taken.


The number of function evaluations of the dual problem.


The norm of the gradient of the last Newton step.

(errno )

On entry, .

Constraint: .

(errno )

Newton iteration fails to converge in iterations.

(errno )

An intermediate eigenproblem could not be solved. This should not occur. Please contact NAG with details of your call.

(errno )

Machine precision is limiting convergence.

The array returned in may still be of interest.


A correlation matrix may be characterised as a real square matrix that is symmetric, has a unit diagonal and is positive semidefinite.

corrmat_nearest applies an inexact Newton method to a dual formulation of the problem, as described by Qi and Sun (2006). It applies the improvements suggested by Borsdorf and Higham (2010).


Borsdorf, R and Higham, N J, 2010, A preconditioned (Newton) algorithm for the nearest correlation matrix, IMA Journal of Numerical Analysis (30(1)), 94–107

Qi, H and Sun, D, 2006, A quadratically convergent Newton method for computing the nearest correlation matrix, SIAM J. Matrix AnalAppl (29(2)), 360–385