# Re: Setting precision in Ruby-GSL calculations?

Dear Ed,

thank you for responding.
Well, I tried transposing as you said too, but then I lost
confidence in the algorithm implemented there, because

for m=[[10,5,-10],[2,-11,10]].to_gsl_matrix, I then get
a matrix u of size (3,2), (it should be 3,3), and u*u.transposed
is

[ 8.889e-001 -2.222e-001 -2.222e-001
-2.222e-001 5.556e-001 -4.444e-001
-2.222e-001 -4.444e-001 5.556e-001 ],

so nowhere near a unit matrix, either …

With respect to the sizes, I am expecting to be able to keep
(m1,m2) somewhere in the range of 50 or below each.

Best regards,

Axel

[email protected] wrote:

[ 8.889e-001 -2.222e-001 -2.222e-001
Axel

Here’s what I get from R:

m=matrix(c(10, 5 ,-10 ,2 ,-11 ,10), nrow=3, ncol=2)
m
[,1] [,2]
[1,] 10 2
[2,] 5 -11
[3,] -10 10
svd(m)
\$d
[1] 18.973666 9.486833

\$u
[,1] [,2]
[1,] -0.2981424 8.944272e-01
[2,] -0.5962848 -4.472136e-01
[3,] 0.7453560 -1.489694e-16

\$v
[,1] [,2]
[1,] -0.7071068 0.7071068
[2,] 0.7071068 0.7071068

m=t(m)
m
[,1] [,2] [,3]
[1,] 10 5 -10
[2,] 2 -11 10
svd(m)
\$d
[1] 18.973666 9.486833

\$u
[,1] [,2]
[1,] -0.7071068 0.7071068
[2,] 0.7071068 0.7071068

\$v
[,1] [,2]
[1,] -0.2981424 8.944272e-01
[2,] -0.5962848 -4.472136e-01
[3,] 0.7453560 -1.859678e-16

M. Edward (Ed) Borasky wrote:

[ 8.889e-001 -2.222e-001 -2.222e-001 -2.222e-001 5.556e-001

[1] 18.973666 9.486833
[2,] 0.7071068 0.7071068
[1] 18.973666 9.486833
[3,] 0.7453560 -1.859678e-16
Oh … I see what’s up now. m is 3x2. Thus its rank must be 2 or less.
So we do the svd (the first one above) and get a 3x2 u, which is
correct. Now multiply u.transpose by u. In R, that’s

m
[,1] [,2]
[1,] 10 2
[2,] 5 -11
[3,] -10 10
svd=svd(m)
svd
\$d
[1] 18.973666 9.486833

\$u
[,1] [,2]
[1,] -0.2981424 8.944272e-01
[2,] -0.5962848 -4.472136e-01
[3,] 0.7453560 -1.489694e-16

\$v
[,1] [,2]
[1,] -0.7071068 0.7071068
[2,] 0.7071068 0.7071068

t(svd\$u) %*% svd\$u
[,1] [,2]
[1,] 1.000000e+00 -1.275693e-16
[2,] -1.275693e-16 1.000000e+00

See if you get the same things when you run it in Ruby/GSL.