File: integration.ml

package info (click to toggle)
ocamlgsl 0.3.5-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,444 kB
  • ctags: 2,901
  • sloc: ml: 7,956; ansic: 6,796; makefile: 303; sh: 87; awk: 13
file content (19 lines) | stat: -rw-r--r-- 625 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
let f alpha x =
  Gc.major ();
  (log (alpha *. x)) /. (sqrt x)

let compute f expected =
  let ws = Gsl_integration.make_ws 1000 in
  let gslfun = f in
  let {Gsl_fun.res = res ;
       Gsl_fun.err = err } = Gsl_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" (Gsl_integration.size ws)

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