# Cosmological distances with ruby

**URL:** <https://www.ruby-forum.com/t/cosmological-distances-with-ruby/59032>\
**Category:** Ruby\
**Created:** [April 28, 2006, 12:49am UTC](https://www.ruby-forum.com/t/cosmological-distances-with-ruby/59032 "2006-04-28T00:49:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cameron\_McBride](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a87d85/32.png) [@Cameron\_McBride](https://www.ruby-forum.com/u/Cameron_McBride)\
**Post date:** [April 28, 2006, 12:49am UTC](https://www.ruby-forum.com/t/cosmological-distances-with-ruby/59032/1 "2006-04-28T00:49:24Z")

</div>

I’m doubtful of any interest, but in the odd chance that someone else  
might want to play, I’m posting this code. If someone does look, all  
comments are welcome (be it ruby style or corrections)!

Attached is a small library that calculates comological distances  
(like light travel time, comoving distances, age of the universe,  
angular size of the horizon) given a specific cosmology. This is  
something I threw together for personal use in solving a homework  
problem or two and making some quick estimates. References are  
included in the comments for further information.

It requires the ruby GSL bindings ([http://rb-gsl.rubyforge.org](http://rb-gsl.rubyforge.org)) for  
numerical integration.

The library also includes some sample usage at the end (which is  
invoked if the script is just run from the command line).

Cameron

p.s. to interested parties, the science / calculations are pretty well  
described by Ned Wright’s page:  
[http://www.astro.ucla.edu/~wright/CosmoCalc.html](http://www.astro.ucla.edu/~wright/CosmoCalc.html)

---

<div class="post-metadata">

**Author:** ![Cameron\_McBride](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a87d85/32.png) [@Cameron\_McBride](https://www.ruby-forum.com/u/Cameron_McBride)\
**Post date:** [April 28, 2006, 4:39am UTC](https://www.ruby-forum.com/t/cosmological-distances-with-ruby/59032/2 "2006-04-28T04:39:29Z")

</div>

On 4/27/06, Cameron McBride [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m doubtful of any interest, but in the odd chance that someone else  
> might want to play, [snip]
> 
> Attached is a small library that calculates comological distances  
> [snip]  
> It requires the ruby GSL bindings ([http://rb-gsl.rubyforge.org](http://rb-gsl.rubyforge.org)) for  
> numerical integration.

Neat. Thanks for the link Cameron.

It’s interesting that there’s two different Ruby bindings to GSL  
(“Ruby/GSL” and ruby-gsl). Any idea why that is? Sometimes when  
there’s two projects like this, it turns out that one is more of a  
straight wrapper, while the other has been worked a little to have  
more of the flavor of the language wrapping it. Is that the case here?

---

<div class="post-metadata">

**Author:** ![Cameron\_McBride](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a87d85/32.png) [@Cameron\_McBride](https://www.ruby-forum.com/u/Cameron_McBride)\
**Post date:** [April 28, 2006, 5:33am UTC](https://www.ruby-forum.com/t/cosmological-distances-with-ruby/59032/3 "2006-04-28T05:33:39Z")

</div>

On Fri, 28 Apr 2006, John G. wrote:

> It’s interesting that there’s two different Ruby bindings to GSL  
> (“Ruby/GSL” and ruby-gsl). Any idea why that is? Sometimes when  
> there’s two projects like this, it turns out that one is more of a  
> straight wrapper, while the other has been worked a little to have  
> more of the flavor of the language wrapping it. Is that the case here?

if anyone is interested in playing with the gsl using the  
one-click-installer  
a pre-compiled version, including narray, is here

[http://www.codeforpeople.com/lib/ruby/rb-gsl-win/](http://www.codeforpeople.com/lib/ruby/rb-gsl-win/)

just grab

[http://www.codeforpeople.com/lib/ruby/rb-gsl-win/rb-gsl-1.7.0.tgz](http://www.codeforpeople.com/lib/ruby/rb-gsl-win/rb-gsl-1.7.0.tgz)

unpack. and run ‘ruby install.rb’.

cheers.

-a

---

<div class="post-metadata">

**Author:** ![Cameron\_McBride](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a87d85/32.png) [@Cameron\_McBride](https://www.ruby-forum.com/u/Cameron_McBride)\
**Post date:** [April 28, 2006, 1:59pm UTC](https://www.ruby-forum.com/t/cosmological-distances-with-ruby/59032/4 "2006-04-28T13:59:56Z")

</div>

On 4/27/06, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 
> 
> [http://www.codeforpeople.com/lib/ruby/rb-gsl-win/](http://www.codeforpeople.com/lib/ruby/rb-gsl-win/)
> 
> just grab
> 
> [http://www.codeforpeople.com/lib/ruby/rb-gsl-win/rb-gsl-1.7.0.tgz](http://www.codeforpeople.com/lib/ruby/rb-gsl-win/rb-gsl-1.7.0.tgz)
> 
> unpack. and run ‘ruby install.rb’.

Very cool, Ara. I’ll remember that link!

Cameron

---

<div class="post-metadata">

**Author:** ![Cameron\_McBride](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a87d85/32.png) [@Cameron\_McBride](https://www.ruby-forum.com/u/Cameron_McBride)\
**Post date:** [April 28, 2006, 2:54pm UTC](https://www.ruby-forum.com/t/cosmological-distances-with-ruby/59032/5 "2006-04-28T14:54:54Z")

</div>

On 4/27/06, John G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> It’s interesting that there’s two different Ruby bindings to GSL  
> (“Ruby/GSL” and ruby-gsl). Any idea why that is? Sometimes when  
> there’s two projects like this, it turns out that one is more of a  
> straight wrapper, while the other has been worked a little to have  
> more of the flavor of the language wrapping it. Is that the case here?

Some might consider that a fair distinction between the two bindings,  
although both camps have included code from the other at one point or  
another. IMO, Arno’s ([http://ruby-gsl.sourceforge.net/](http://ruby-gsl.sourceforge.net/)) is a bit more  
of a straight forward binding whereas Yoshiki added a few things to  
round some corners (and hence it’s the one I use). Also, Yoshiki put  
a good deal of time into documentation - which is always a good thing!

Cameron

---

<div class="post-metadata">

**Author:** ![Cameron\_McBride](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a87d85/32.png) [@Cameron\_McBride](https://www.ruby-forum.com/u/Cameron_McBride)\
**Post date:** [April 28, 2006, 3:53pm UTC](https://www.ruby-forum.com/t/cosmological-distances-with-ruby/59032/6 "2006-04-28T15:53:10Z")

</div>

Awesome! This’ll show James Gosling that Ruby’s perfectly fine for  
interplanetary navigation! 😃

On 4/28/06, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > although both camps have included code from the other at one point or  
> > -a  
> > –  
> > be kind whenever possible… it is always possible.
> 
> - h.h. the 14th dali lama

–  
-Dan Nugent

Don’t Feel Like Typing? Send me a voicemail:  
[http://odeo.com/sendmeamessage/DanNugent](http://odeo.com/sendmeamessage/DanNugent)

---

<div class="post-metadata">

**Author:** ![Cameron\_McBride](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a87d85/32.png) [@Cameron\_McBride](https://www.ruby-forum.com/u/Cameron_McBride)\
**Post date:** [April 28, 2006, 3:22pm UTC](https://www.ruby-forum.com/t/cosmological-distances-with-ruby/59032/7 "2006-04-28T15:22:48Z")

</div>

On Fri, 28 Apr 2006, Cameron McBride wrote:

> straight forward binding whereas Yoshiki added a few things to round some  
> corners (and hence it’s the one I use). Also, Yoshiki put a good deal of  
> time into documentation - which is always a good thing!

lastly, yoshiki’s versions allows one to intermix narray and gsl  
routines  
which is really sweet.

cheers.

-a
