promlem about svdcmp


alan
12-11-2003, 04:20 PM
Hi,
I use the Fortran 77 Numerical Recipes programs (I got them from MS Fortran PowerStation ver4.0, and they are upgraded to the 2.10 version) to verify the C++ Numerical Recipes programs because the C++ codes are input from the book. When I ran the xsvdcmp.cpp and xsvdcmp.for (I couldn¡¯t find the input problem.), I found:
When the Number of Rows equals the Number of Columns, I can get the same solution.
When the Number of Rows is greater than the Number of Columns, I can¡¯t get the same solution. I can¡¯t find the reasons, Please help. Thank you.

Here is the original matrix and the two solutions ran by CPP program and by Fortran77 program.
The matrix is:
Number of Rows, Columns
5,3
Matrix
1.0 2.0 3.0
2.0 3.0 4.0
3.0 4.0 5.0
4.0 5.0 6.0
5.0 6.0 7.0

The CPP solution:
-0.219236 -0.742924 0.530877
-0.321266 -0.443608 -0.282197
-0.423296 -0.144292 -0.718999
-0.525326 0.155023 0.161080
-0.627356 0.454339 0.309239

The Fortran77 solution:
-0.219236 -0.742923 0.558841
-0.321266 -0.443608 -0.814382
-0.423296 -0.144292 0.045120
-0.525326 0.155023 0.117540
-0.627356 0.454339 0.092880

Saul Teukolsky
12-11-2003, 07:12 PM
Dear Alan,

Make sure you have included the 2 bug fixes described in Official Bug Reports for svdcmp.cpp. (These bugs were fixed in v 2.11).

Saul Teukolsky

alan
12-11-2003, 10:08 PM
I fixed those two bugs before I posted, but the problem is still there. Thank you.

Saul Teukolsky
12-12-2003, 07:51 AM
Hi Alan,

The result you have in both cases is correct, as you can check by calculating u*w*(v-transpose). The SVD is not unique, as discussed in the text, and the only way to check it is to form the product of the 3 matrices.

Saul Teukolsky

alan
12-12-2003, 10:52 AM
Thank you very much. By the way, Numerical Recipes is really a great book.:p
But I think if the svdcmp.cpp and the svdcmp.for are based on the same algorithm, the calculationg results to the same problem are also the same.