## File: Special-Functions-Examples.html

package info (click to toggle)
gsl-ref-html 2.3-1
• area: non-free
• in suites: bullseye, buster, sid
• size: 6,876 kB
• ctags: 4,574
• sloc: makefile: 35
 file content (147 lines) | stat: -rw-r--r-- 5,493 bytes parent folder | download
 `123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147` `````` GNU Scientific Library – Reference Manual: Special Functions Examples

7.33 Examples

The following example demonstrates the use of the error handling form of the special functions, in this case to compute the Bessel function J_0(5.0),

#include <stdio.h> #include <gsl/gsl_errno.h> #include <gsl/gsl_sf_bessel.h>  int main (void) {   double x = 5.0;   gsl_sf_result result;    double expected = -0.17759677131433830434739701;      int status = gsl_sf_bessel_J0_e (x, &result);    printf ("status  = %s\n", gsl_strerror(status));   printf ("J0(5.0) = %.18f\n"           "      +/- % .18f\n",            result.val, result.err);   printf ("exact   = %.18f\n", expected);   return status; }

Here are the results of running the program,

\$ ./a.out
status  = success J0(5.0) = -0.177596771314338264       +/-  0.000000000000000193 exact   = -0.177596771314338292

The next program computes the same quantity using the natural form of the function. In this case the error term result.err and return status are not accessible.

#include <stdio.h> #include <gsl/gsl_sf_bessel.h>  int main (void) {   double x = 5.0;   double expected = -0.17759677131433830434739701;      double y = gsl_sf_bessel_J0 (x);    printf ("J0(5.0) = %.18f\n", y);   printf ("exact   = %.18f\n", expected);   return 0; }

The results of the function are the same,

\$ ./a.out
J0(5.0) = -0.177596771314338264 exact   = -0.177596771314338292
``````