File: integration_ex.ml

package info (click to toggle)
ocamlgsl 1.19.1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,628 kB
  • ctags: 2,812
  • sloc: ml: 17,194; ansic: 7,445; makefile: 24
file content (21 lines) | stat: -rw-r--r-- 611 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
open Gsl

let f alpha x =
  Gc.major ();
  (log (alpha *. x)) /. (sqrt x)

let compute f expected =
  let ws = Integration.make_ws 1000 in
  let gslfun = f in
  let {Fun.res = res ;
       Fun.err = err } = Integration.qags gslfun 
      ~a:0. ~b:1. ~epsabs:0. ~epsrel:1e-7 ws in
  Printf.printf "result          = % .18f\n" res ;
  Printf.printf "exact result    = % .18f\n" expected ;
  Printf.printf "estimated error = % .18f\n" err ;
  Printf.printf "actual error    = % .18f\n" (res -. expected) ;
  Printf.printf "intervals = %d\n" (Integration.size ws)

let _ = 
  Error.init ();
  compute (f 1.0) (-4.)