Menu

GSL (Gnu Scientific Library) Success?

2002-12-21
2012-09-26
  • Nobody/Anonymous

    I have mumbled in a few posts about having used the GSL with Cygwin, because it has neat randon number and special function stuff in it.  In my one opportunity to help someone trying to use it, I failed miserably.  This morning, I took a different tack, and had some success.

    First, I discovered here at SourceForge a version of the GSL.  Its GSL 1.0, which is not the newest (1.3 is, though Cygwin only uses 1.1).  Anyway, you can find it here, just look for gsl:

    http://sourceforge.net/project/showfiles.php?group_id=23617

    I got the lib and bin files, and parsed out the header files to the Dev include directory, the library stuff to the dev lib directory, and the bin stuff to the dev bin directory.  One note, the header files I placed in a gsl subdirectory under the include directory, i.e. c:\dev-cpp\include\gsl

    If you want to compile with this stuff, you have to make sure to add -lgsl to your command line options for your compiler. (Forgive me if I am stating the obvious)

    OK, here is a "simple" example program which give you values for the Bessel function and Airy function....trust me, they are really interesting!  It is written as a C program, so I called it gsl_test.c

    #include <stdio.h>
    #include <gsl/gsl_sf_bessel.h>
    #include <gsl/gsl_sf_airy.h>
    #include <stdlib.h>

    int main(void)
    {
        double x = 5.0;

        double y = gsl_sf_bessel_J1(x);

        double z = gsl_sf_airy_Ai(0.20,1);

        printf("J0(%g) = %.18e\n",x,y);

        printf("Airy = %g\n",z);
       
        system("pause");

        return 0;
    }

    Here is an example of a simple test of random numbers:

    #include <stdio.h>
    #include <gsl/gsl_rng.h>
    #include <stdlib.h>

    gsl_rng * r;  /* global generator */

    int
    main (void)
    {
      const gsl_rng_type * T;

      gsl_rng_env_setup();

      T = gsl_rng_default;
      r = gsl_rng_alloc (T);
     
      printf("generator type: %s\n", gsl_rng_name (r));
      printf("seed = %u\n", gsl_rng_default_seed);
      printf("first value = %u\n", gsl_rng_get (r));
      system("pause");
      return 0;
    }

    Since random numbers seems to be of interest, here is a pointer to the part of the manual covering that topic:

    http://sources.redhat.com/gsl/ref/gsl-ref_17.html

    Wayne

     
    • Nobody/Anonymous

      Wayne,

      thank you very much for helping me out with this. It was simple enough that without much effort I got everything working including your test program. Thanks again.

      josh

       
    • Nobody/Anonymous

      Great!  You made my day!  Good luck!

      Wayne

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.