In Ruby/GSL, the GSL physical constants are provided as Ruby constants under the
GSL::CONST::MKSA or GSL::CONST:CGSM modules.
For example, the GSL C constant which gives the speed of light
GSL_CONST_MKSA_SPEED_OF_LIGHT is represented by
the Ruby constant GSL::CONST::MKSA::SPEED_OF_LIGHT.
See the GSL manual for complete list of the defined constants.
The following program demonstrates the use of the physical constants in a calculation. In this case, the goal is to calculate the range of light-travel times from Earth to Mars.
require 'gsl'
include GSL::CONST::MKSA
puts("In MKSA unit")
c = SPEED_OF_LIGHT;
au = ASTRONOMICAL_UNIT;
minutes = MINUTE;
# distance stored in meters
r_earth = 1.00 * au;
r_mars = 1.52 * au;
t_min = (r_mars - r_earth) / c;
t_max = (r_mars + r_earth) / c;
printf("light travel time from Earth to Mars:\n");
printf("c = %e [m/s]\n", c)
printf("AU = %e [m]\n", au)
printf("minutes = %e [s]\n", minutes)
printf("minimum = %.1f minutes\n", t_min / minutes);
printf("maximum = %.1f minutes\n\n", t_max / minutes);