2.1.17.6.8 ocmath_svd
Description
Singular-value decomposition for matrix of double.
A=U*S*V', A is m by n, U is m by m, S is a vector to store diagnal elements of matrix of size min(m,n),
V is n by n, it's the same as Matlab
Syntax
int ocmath_svd( int m, int n, double * pSource, double * pU, double * pS, double * pV )
Parameters
- m
- [input] row number of matrix A
- n
- [input] column number of matrix A
- pSource
- [input] pointer to the original matrix A
- pU
- [output] pointer to matrix U, of size m by m
- pS
- [output] pointer to the singular-value vector, of size min(m,n)
- pV
- [output] pointer to matrix V, of size n by n
Return
= OE_NOERROR: success
= OE_INVALID_SIZE: m < 1 or n < 1
= OE_NULL_POINTER: pointers pSource, pU, pS or pV is NULL
= NE_CONVERGENCE: <value> off-diagonals did not converge. The arrays d and e contain the diagonal and off-diagonal elements, respectively, of a bidiagonal matrix orthogonally equivalent to B.
= NE_ALLOC_FAIL: Memory allocation failed.
= NE_BAD_PARAM: On entry, parameter hvaluei had an illegal value.
= NE_INTERNAL_ERROR: An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please consult NAG for assistance.
Examples
EX1
void ocmath_svd_ex1()
{
matrix matSource={{2,3,5,7},{11,13,17,19},{23,29,31,37}};
matrix matU;
matrix matS;
matrix matV;
int nNumCols = matSource.GetNumCols();
int nNumRows = matSource.GetNumRows();
int nMinSize = nNumCols > nNumRows ? nNumRows : nNumCols;
matU.SetSize(nNumRows, nNumRows);
matS.SetSize(nMinSize, nMinSize);
matV.SetSize(nNumCols, nNumCols);
vector vecS;
vecS.SetSize(nMinSize);
ocmath_svd(nNumRows, nNumCols, matSource, matU, vecS, matV);
matS.SetDiagonal(vecS, 0);
}
Remark
See Also
Header to Include
origin.h
Reference
nag_dgebrd(f08kec)nag_dgebrd(f08kec), nag_dorgbr(f08kfc)nag_dgebrd(f08kec)nag_dgebrd(f08kec), nag_dorgbr(f08kfc), nag_dbdsqr(f08mec)nag_dgebrd(f08kec)nag_dgebrd(f08kec), nag_dorgbr(f08kfc)nag_dgebrd(f08kec)nag_dgebrd(f08kec), nag_dorgbr(f08kfc), nag_dbdsqr(f08mec), Nag Manual
|