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

Syntax

C#
public static void g02aa(
	double[,] g,
	int n,
	double errtol,
	int maxits,
	int maxit,
	double[,] x,
	out int iter,
	out int feval,
	out double nrmgrd,
	out int ifail
)
Visual Basic
Public Shared Sub g02aa ( _
	g As Double(,), _
	n As Integer, _
	errtol As Double, _
	maxits As Integer, _
	maxit As Integer, _
	x As Double(,), _
	<OutAttribute> ByRef iter As Integer, _
	<OutAttribute> ByRef feval As Integer, _
	<OutAttribute> ByRef nrmgrd As Double, _
	<OutAttribute> ByRef ifail As Integer _
)
Visual C++
public:
static void g02aa(
	array<double,2>^ g, 
	int n, 
	double errtol, 
	int maxits, 
	int maxit, 
	array<double,2>^ x, 
	[OutAttribute] int% iter, 
	[OutAttribute] int% feval, 
	[OutAttribute] double% nrmgrd, 
	[OutAttribute] int% ifail
)
F#
static member g02aa : 
        g : float[,] * 
        n : int * 
        errtol : float * 
        maxits : int * 
        maxit : int * 
        x : float[,] * 
        iter : int byref * 
        feval : int byref * 
        nrmgrd : float byref * 
        ifail : int byref -> unit 

Parameters

g
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, n]
Note: dim1 must satisfy the constraint: dim1n
On entry: G, the initial matrix.
On exit: a symmetric matrix 12G+GT with the diagonal set to I.
n
Type: System..::..Int32
On entry: the size of the matrix G.
Constraint: n>0.
errtol
Type: System..::..Double
On entry: the termination tolerance for the Newton iteration. If errtol0.0 then n×machine precision is used.
maxits
Type: System..::..Int32
On entry: maxits specifies the maximum number of iterations used for the iterative scheme used to solve the linear algebraic equations at each Newton step.
If maxits0, 2×n is used.
maxit
Type: System..::..Int32
On entry: specifies the maximum number of Newton iterations.
If maxit0, 200 is used.
x
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, n]
Note: dim1 must satisfy the constraint: dim1n
On exit: contains the nearest correlation matrix.
iter
Type: System..::..Int32%
On exit: the number of Newton steps taken.
feval
Type: System..::..Int32%
On exit: the number of function evaluations of the dual problem.
nrmgrd
Type: System..::..Double%
On exit: the norm of the gradient of the last Newton step.
ifail
Type: System..::..Int32%
On exit: ifail=0 unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

Description

A correlation matrix may be characterised as a real square matrix that is symmetric, has a unit diagonal and is positive semidefinite.
g02aa 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).

References

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

Error Indicators and Warnings

Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface (LDG, LDX) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
ifail=1
On entry, ldg=value and n=value.
Constraint: ldgn.
On entry, ldx=value and n=value.
Constraint: ldxn.
On entry, n=value.
Constraint: n>0.
ifail=2
Newton iteration fails to converge in value iterations.
ifail=3
Machine precision is limiting convergence.
The array returned in x may still be of interest.
ifail=4
An intermediate eigenproblem could not be solved. This should not occur. Please contact NAG with details of your call.
ifail=-999
Dynamic memory allocation failed.
ifail=-9000
An error occured, see message report.
ifail=-6000
Invalid Parameters value
ifail=-4000
Invalid dimension for array value
ifail=-8000
Negative dimension for array value
ifail=-6000
Invalid Parameters value

Accuracy

The returned accuracy is controlled by errtol and limited by machine precision.

Parallelism and Performance

None.

Further Comments

Arrays are internally allocated by g02aa. The total size of these arrays is 11×n+3×n×n+max2×n×n+6×n+1,120+9×n real elements and 5×n+3 integer elements.

Example

This example finds the nearest correlation matrix to:
G=2-100-12-100-12-100-12

Example program (C#): g02aae.cs

Example program data: g02aae.d

Example program results: g02aae.r

See Also