Interface to GNU GSL Numerical Integration.
Library hides memory allocation and other low level C stuff.
GNU GSL has to be installed separately. Tested for version 2.5.
Naming of functions and keywords follow GNU GSL documentation https://www.gnu.org/software/gsl/doc/html/integration.html
The source code is distributed under the GNU General Public License.
(require gsl-integration) (define (f x) ( / (log x) (sqrt x))) (define expected (- 4.0)) (define res (qags f 0 1 #:epsrel 1e-07)) (if (= 0 (first res)) (begin (displayln (string-append "result = " (~a (second res)))) (displayln (string-append "exact result = " (~a expected))) (displayln (string-append "result = " (~a (second res)))) (displayln (string-append "estimated error = " (~a (third res)))) (displayln (string-append "actual error = " (~a (- (second res) expected))))) (error "status = " (~a (first res))))
; result = -4.000000000000085 ; exact result = -4.0 ; result = -4.000000000000085 ; estimated error = 1.354472090042691e-13 ; actual error = -8.526512829121202e-1
For more examples look at test.rkt source file.
Tip: When working with math formulas it is recommended to use a infix library, for better readability. For example: https://pkgs.racket-lang.org/package/infix
The functions will always return a list.
First element is status code. Success when code = 0, otherwise error.
Success list: 0, result. Thereafter one or both (see GNU GSL documentation): abserr , neveal.
Error list: codenr, gsl-symbol, message.
(0 result abserr neval)
(codenr gsl-symbol message)
(or/c (list/c integer? real? real?) (list/c integer? symbol? string?)) f : (-> flonum? flonum?) a : real? b : real? epsabs : real? = 0 epsrel : real? = 1e-08 limit : exact-positive-integer? = 1000 key : exact-positive-integer? = 2
Some linux systems have precompiled package for GNU GSL library. Howeever this package can be of an older version. It is recommended to compile and install GNU GSL library from source. Beware that installation directory from source can be different that from precompiled package.
If you get an error that it can not find Romberg, but not error on the other functions: You have and older version of GNU GSL on our system. Romberg was added at version 2.5
If you get error: ffi-lib: couldn’t open "libgslcblas.so" (libgslcblas.so: cannot open shared object file: No such file or directory)
Solution: Edit ~/.bashrc