PDA

View Full Version : svdcmp error??


shade
04-04-2006, 03:24 PM
In "NR in C" it is stated that this algorithm can be checked by just generating a random matrix, squeezing it through the procedure and then verify by the matrixmultiplications:
2.6.1: A=U*W*V^T
and
2.6.4: U^T * U = V^T * V = 1
...

I've spend the beter part of the weekend translating this algorithm from C to pascal(as part of a chiĀ² minimalisation algo)...to find out that I seem to have killed it. (some research on the internet provided me with the original pascal code, and some thinkering later i was also able to check my results with that algorithm...and the results are almost the sam(ie bad).)

Is this known or is this a personal mistake?
results from my translation: (the first A matrix is the original one)

A matrix
--------------
1.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000
0.00000000000000E+0000 3.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000
0.00000000000000E+0000 0.00000000000000E+0000 2.00000000000000E+0000 0.00000000000000E+0000
0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 9.90000000000000E+0001
0.00000000000000E+0000 1.20000000000000E+0000 3.00000000000000E-0001 0.00000000000000E+0000

=========================

U matrix
--------------
-1.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000
-0.00000000000000E+0000-9.26095750288643E-0001 8.39053477801660E-0002 0.00000000000000E+0000
-0.00000000000000E+0000-3.48902619183154E-0002-9.89825835932518E-0001 0.00000000000000E+0000
-0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000-1.00000000000000E+0000
-0.00000000000000E+0000-3.75671839403204E-0001-1.14911736277811E-0001 0.00000000000000E+0000

=========================

V matrix
--------------
-1.00000000000000E+0000 0.00000000000000E+0000-0.00000000000000E+0000-0.00000000000000E+0000
-0.00000000000000E+0000-9.98407019352556E-0001 5.64218371514578E-0002-0.00000000000000E+0000
-0.00000000000000E+0000 5.64218371514578E-0002 9.98407019352556E-0001-0.00000000000000E+0000
-0.00000000000000E+0000 0.00000000000000E+0000-0.00000000000000E+0000-1.00000000000000E+0000

=========================

W matrix
--------------
1.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000
0.00000000000000E+0000 3.23424554871796E+0000 0.00000000000000E+0000 0.00000000000000E+0000
0.00000000000000E+0000 0.00000000000000E+0000 2.01733877437530E+0000 0.00000000000000E+0000
0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 9.90000000000000E+0001

=========================

A=U*W*V^T matrix
--------------
1.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000
0.00000000000000E+0000 3.00000000000000E+0000-5.62700927519977E-0017 0.00000000000000E+0000
0.00000000000000E+0000 1.76996004658259E-0017-2.00000000000000E+0000 0.00000000000000E+0000
0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 9.90000000000000E+0001
0.00000000000000E+0000 1.20000000000000E+0000-3.00000000000000E-0001 0.00000000000000E+0000

=========================

V*V^T= 1
--------------
1.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000
0.00000000000000E+0000 1.00000000000000E+0000-2.58514455502012E-0018 0.00000000000000E+0000
0.00000000000000E+0000-2.58514455502012E-0018 1.00000000000000E+0000 0.00000000000000E+0000
0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 1.00000000000000E+0000

=========================

U*U^T= 1
--------------
1.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000
0.00000000000000E+0000 8.64693446088795E-0001-5.07399577167019E-0002 0.00000000000000E+0000 3.38266384778013E-0001
0.00000000000000E+0000-5.07399577167019E-0002 9.80972515856237E-0001 0.00000000000000E+0000 1.26849894291755E-0001
0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 1.00000000000000E+0000 0.00000000000000E+0000
0.00000000000000E+0000 3.38266384778013E-0001 1.26849894291755E-0001 0.00000000000000E+0000 1.54334038054968E-0001

=========================



and the results from the code i found on the internet:

A matrix
--------------
1.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000
0.00000000000000E+0000 3.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000
0.00000000000000E+0000 0.00000000000000E+0000 2.00000000000000E+0000 0.00000000000000E+0000
0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 9.90000000000000E+0001
0.00000000000000E+0000 1.20000000000000E+0000 3.00000000000000E-0001 0.00000000000000E+0000

=========================

U matrix
--------------
-1.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000
-0.00000000000000E+0000-9.26095750288643E-0001 8.39053477801660E-0002 0.00000000000000E+0000
-0.00000000000000E+0000-3.48902619183154E-0002-9.89825835932518E-0001 0.00000000000000E+0000
-0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000-1.00000000000000E+0000
-0.00000000000000E+0000-3.75671839403204E-0001-1.14911736277811E-0001 0.00000000000000E+0000

=========================

V matrix
--------------
-1.00000000000000E+0000 0.00000000000000E+0000-0.00000000000000E+0000-0.00000000000000E+0000
-0.00000000000000E+0000-9.98407019352556E-0001 5.64218371514578E-0002-0.00000000000000E+0000
-0.00000000000000E+0000-5.64218371514578E-0002-9.98407019352556E-0001-0.00000000000000E+0000
-0.00000000000000E+0000 0.00000000000000E+0000-0.00000000000000E+0000-1.00000000000000E+0000

=========================

W matrix
--------------
0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000
0.00000000000000E+0000 1.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000
0.00000000000000E+0000 0.00000000000000E+0000 3.23424554871796E+0000 0.00000000000000E+0000
0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 2.01733877437530E+0000

=========================

A=U*W*V^T matrix
--------------
0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000
0.00000000000000E+0000 9.39931719702450E-0001-2.18686186011273E-0001 0.00000000000000E+0000
0.00000000000000E+0000-1.45790790674182E-0001 3.19820870419345E+0000 0.00000000000000E+0000
0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 2.01733877437530E+0000
0.00000000000000E+0000 3.54104069279852E-0001 3.92256831224509E-0001 0.00000000000000E+0000

=========================

V*V^T= 1
--------------
1.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000
0.00000000000000E+0000 1.00000000000000E+0000 2.58514455502012E-0018 0.00000000000000E+0000
0.00000000000000E+0000 2.58514455502012E-0018 1.00000000000000E+0000 0.00000000000000E+0000
0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 1.00000000000000E+0000

=========================

U*U^T= 1
--------------
1.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000
0.00000000000000E+0000 8.64693446088795E-0001-5.07399577167019E-0002 0.00000000000000E+0000 3.38266384778013E-0001
0.00000000000000E+0000-5.07399577167019E-0002 9.80972515856237E-0001 0.00000000000000E+0000 1.26849894291755E-0001
0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 1.00000000000000E+0000 0.00000000000000E+0000
0.00000000000000E+0000 3.38266384778013E-0001 1.26849894291755E-0001 0.00000000000000E+0000 1.54334038054968E-0001

=========================


thx.

shade
04-05-2006, 07:24 PM
:eek: found the source of the problem... i switched an index i and j in 1 single place....woeps