# Re: Setting precision in Ruby-GSL calculations?

**URL:** <https://www.ruby-forum.com/t/re-setting-precision-in-ruby-gsl-calculations/100624>\
**Category:** Ruby\
**Created:** [July 31, 2006, 12:04am UTC](https://www.ruby-forum.com/t/re-setting-precision-in-ruby-gsl-calculations/100624 "2006-07-31T00:04:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 31, 2006, 12:04am UTC](https://www.ruby-forum.com/t/re-setting-precision-in-ruby-gsl-calculations/100624/1 "2006-07-31T00:04:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 31, 2006, 1:01am UTC](https://www.ruby-forum.com/t/re-setting-precision-in-ruby-gsl-calculations/100624/2 "2006-07-31T01:01:03Z")

</div>

removed\_email\_address@domain.invalid 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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 31, 2006, 1:12am UTC](https://www.ruby-forum.com/t/re-setting-precision-in-ruby-gsl-calculations/100624/3 "2006-07-31T01:12:27Z")

</div>

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.
