# Ublas :

Subject: [ublas] GESVD using bindings20081116 and CLapack 3.1.1
From: Yashodhan Nevatia (yashodhan.nevatia_at_[hidden])
Date: 2009-09-07 08:42:18

Hi all,

I am new to using UBlas/CLapack. I am using CLapack 3.1.1 with boost-numeric-bindings-20081116 (under Visual Studio 2008).

I have 2 questions regarding the use of the gesvd function.

1) Values of the U and the Vt matrix?

Finding the SVD of a 3x3 matrix, while trying to check the validity of the solution, I multiply the outputs (I check if A == U S Vt). Since the answer was not the original matrix, I took a look to see the values of the U and the Vt matrix seem swapped (compared to a MATLAB execution). In fact Vt S U == A.

The code fragment is:

double min_delta=0.00001;
matrix<double> U(3,3);
matrix<double> Vt(3,3);
matrix<double> A(3,3);
matrix<double> S_mat(3,3);
boost::numeric::ublas::vector<double> S(3);

for (unsigned i = 0; i < A.size1 (); ++ i)
{
for (unsigned j = 0; j < A.size2 (); ++ j)
{
A(i, j) = (3 * i + j);
}
}

gesvd('A','A',A,S,U,Vt);

//Init S_mat
for (unsigned i = 0; i < S_mat.size1 (); ++ i)
{
for (unsigned j = 0; j < S_mat.size2 (); ++ j)
{
S_mat(i, j) = 0.0;
}
if(i<S_mat.size2 ()) S_mat(i,i)=S(i);
}

matrix<double> res_t=prec_prod(U,S_mat);
matrix<double> res=prec_prod(res_t,Vt);

//Comparing values
for (unsigned i = 0; i < res.size1 (); ++ i)
{
for (unsigned j = 0; j < res.size2 (); ++ j)
{
CPPUNIT_ASSERT(fabs(res(i,j) - (3 * i + j))<min_delta);
}
}

2) SVD of a non square matrix:

I need to caluclate the SVD of a non square matrix. I need the singular values and the right singular vectors (Vt).

I tried using gesvd the same way as above, it triggers a failed assert:

1>Assertion failed: info == 0, file d:\spaceapps\projects\wear_ga\yashodev\wear\libraries\boost-numeric-bindings\boost\numeric\bindings\lapack\gesvd.hpp, line 213
1>** On entry to DGESVD, parameter number 6 had an illegal value

The code is:

matrix<double> U(5,5);
matrix<double> Vt(3,3);
matrix<double> A(5,3);
boost::numeric::ublas::vector<double> S(3);

for (unsigned i = 0; i < A.size1 (); ++ i)
{
for (unsigned j = 0; j < A.size2 (); ++ j)
{
A(i, j) = (3 * i + j);
}
}

gesvd('A','A',A,S,U,Vt);

Any help or suggestions on tackling these issues would be greatly appreciated!

Thank you,

Yashodhan

```--
Yashodhan Nevatia
Systems Engineer
Space Applications Services
Leuvensesteenweg 325
B-1932 Zaventem
Belgium
Tel:  +32 (0)2-721.54.84
Fax:  +32 (0)2-721.54.44
URL: www.spaceapplications.com
--
Yashodhan Nevatia
Systems Engineer
Space Applications Services
Leuvensesteenweg 325
B-1932 Zaventem
Belgium
Tel:  +32 (0)2-721.54.84
Fax:  +32 (0)2-721.54.44
URL: www.spaceapplications.com
--
Yashodhan Nevatia
Systems Engineer
Space Applications Services
Leuvensesteenweg 325
B-1932 Zaventem
Belgium
Tel:  +32 (0)2-721.54.84
Fax:  +32 (0)2-721.54.44
URL: www.spaceapplications.com
```