SVD
Description
Singular value decomposition of complex matrix
Get the diagonal matrix of Singular value decomposition of complex matrix
Get the diagonal matrix of Singular value decomposition of real matrix
Singular value decomposition of real matrix
Syntax
int SVD( matrix<complex> & matSource, matrix & matS, matrix<complex> & matU, matrix<complex> & matV )
int SVD( matrix<complex> & matSource, matrix & matS )
int SVD( matrix & matSource, matrix & matS )
int SVD( matrix & matSource, matrix & matS, matrix & matU, matrix & matV )
Parameters
- matSource
- [input]The source matrix
- matS
- [output]A diagonal matrix of Singular value decomposition
- matU
- [output]A unitary matrix of Singular value decomposition
- matV
- [input]A unitary matrix of Singular value decomposition
- matSource
- [input]The source matrix
- matS
- [output]A diagonal matrix of Singular value decomposition
- matSource
- [input]The source matrix
- matS
- [output]A diagonal matrix of Singular value decomposition
- matSource
- [input]The source matrix
- matS
- [output]A diagonal matrix of Singular value decomposition
- matU
- [output]A unitary matrix of Singular value decomposition
- matV
- [input]A unitary matrix of Singular value decomposition
Return
Returns 0 on successful exit
Returns 0 on successful exit
Returns 0 on successful exit
Examples
EX1
int SVD_ex1()
{
matrix<complex> matSource = {{1+3i, 2+4i, 3+2i},{5+8i, 6+9i, 7+10i},{9+12i, 10+1i, 11+3i}};
printf("The source complex matrix:\n");
int ii, jj;
int nNumCols = matSource.GetNumCols();
int nNumRows = matSource.GetNumRows();
for(ii = 0; ii < nNumRows; ii++)
{
for(jj = 0; jj < nNumCols; jj++)
out_complex("", matSource[ii][jj]);
printf("\n");
}
matrix matS;
matrix<complex> matU, matV;
int nRet = SVD(matSource, matS, matU, matV);
if(nRet != 0)
{
printf("SVD failed!");
return -1;
}
printf("The result three matrices are:\n");
printf("S:\n");
for(ii = 0; ii < nNumRows; ii++)
{
for(jj = 0; jj < nNumCols; jj++)
printf("\t%f", matS[ii][jj]);
printf("\n");
}
printf("U:\n");
for(ii = 0; ii < matU.GetNumRows(); ii++)
{
for(jj = 0; jj < matU.GetNumCols(); jj++)
out_complex("", matU[ii][jj]);
printf("\n");
}
printf("V:\n");
for(ii = 0; ii < matV.GetNumRows(); ii++)
{
for(jj = 0; jj < matV.GetNumCols(); jj++)
out_complex("\t", matV[ii][jj]);
printf("\n");
}
return 0;
}
EX2
int SVD_ex2()
{
matrix<complex> matSource = {{1+3i, 2+4i, 3+2i},{5+8i, 6+9i, 7+10i},{9+12i, 10+1i, 11+3i}};
printf("The source complex matrix:\n");
int ii, jj;
int nNumCols = matSource.GetNumCols();
int nNumRows = matSource.GetNumRows();
for(ii = 0; ii < nNumRows; ii++)
{
for(jj = 0; jj < nNumCols; jj++)
out_complex("", matSource[ii][jj]);
printf("\n");
}
matrix matS;
//matrix<complex> matU, matV;
int nRet = SVD(matSource, matS);
if(nRet != 0)
{
printf("SVD failed!");
return -1;
}
printf("The result matrix:\n");
printf("S:\n");
for(ii = 0; ii < nNumRows; ii++)
{
for(jj = 0; jj < nNumCols; jj++)
printf("\t%f", matS[ii][jj]);
printf("\n");
}
return 0;
}
EX3
int SVD_ex3()
{
matrix matSource = {{1,2,3},{5,6,7},{9,10,11}};
printf("The source complex matrix:\n");
int ii, jj;
int nNumCols = matSource.GetNumCols();
int nNumRows = matSource.GetNumRows();
for(ii = 0; ii < nNumRows; ii++)
{
for(jj = 0; jj < nNumCols; jj++)
out_complex("", matSource[ii][jj]);
printf("\n");
}
matrix matS;
//matrix<complex> matU, matV;
int nRet = SVD(matSource, matS);
if(nRet != 0)
{
printf("SVD failed!");
return -1;
}
printf("The result matrix:\n");
printf("S:\n");
for(ii = 0; ii < nNumRows; ii++)
{
for(jj = 0; jj < nNumCols; jj++)
printf("\t%f", matS[ii][jj]);
printf("\n");
}
return 0;
}
EX4
int SVD_ex4()
{
matrix matSource = {{1,2,3},{5,6,7},{9,10,11}};
printf("The source complex matrix:\n");
int ii, jj;
int nNumCols = matSource.GetNumCols();
int nNumRows = matSource.GetNumRows();
for(ii = 0; ii < nNumRows; ii++)
{
for(jj = 0; jj < nNumCols; jj++)
printf("\t%f", matSource[ii][jj]);
printf("\n");
}
matrix matS, matU, matV;
int nRet = SVD(matSource, matS, matU, matV);
if(nRet != 0)
{
printf("SVD failed!");
return -1;
}
printf("The result three matrices are:\n");
printf("S:\n");
for(ii = 0; ii < nNumRows; ii++)
{
for(jj = 0; jj < nNumCols; jj++)
printf("\t%f", matS[ii][jj]);
printf("\n");
}
printf("U:\n");
for(ii = 0; ii < matU.GetNumRows(); ii++)
{
for(jj = 0; jj < matU.GetNumCols(); jj++)
printf("\t%f", matU[ii][jj]);
printf("\n");
}
printf("V:\n");
for(ii = 0; ii < matV.GetNumRows(); ii++)
{
for(jj = 0; jj < matV.GetNumCols(); jj++)
printf("\t%f", matV[ii][jj]);
printf("\n");
}
return 0;
}
Remark
See Also
header to Include
origin.h
Reference
|