An Example Program - GNU Scientific Library -- Reference Manual
Description: GNU Scientific Library -- Reference Manual

Next: Compiling and Linking, Up: Using the library

### 2.1 An Example Program

The following short program demonstrates the use of the library by computing the value of the Bessel function J_0(x) for x=5,

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

         int
         main (void)
         {
           double x = 5.0;
           double y = gsl_sf_bessel_J0 (x);
           printf ("J0(%g) = %.18e\n", x, y);
           return 0;
         }

The output is shown below, and should be correct to double-precision accuracy,1

         J0(5) = -1.775967713143382920e-01

The steps needed to compile this program are described in the following sections.

#### Footnotes

[1] The last few digits may vary slightly depending on the compiler and platform used—this is normal.

The GNU Scientific Library - a free numerical library licensed under the GNU GPL
Back to the GNU Scientific Library Homepage