File: qagi2.rb

package info (click to toggle)
ruby-gsl 2.1.0.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,892 kB
  • ctags: 5,459
  • sloc: ansic: 61,660; ruby: 15,656; sh: 19; makefile: 10
file content (49 lines) | stat: -rwxr-xr-x 976 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env ruby
require 'gsl'
include GSL
include Math

f = Function.alloc{ |x|
  exp(-x*x)
}

exact = sqrt(PI)

result, = f.qagi
puts("QAGI")
puts("exp(-x*x), x = -infty --- +infty")
printf("exact  = %.18f\n", exact)
printf("result = %.18f\n\n", result)

p Integration.qagi(f)

w = Integration::Workspace.alloc(1000)
xmin = 0.0

puts("QAGIU")
result, = f.integration_qagiu(xmin, [0, 1e-6], w)
puts("exp(-x*x), x = 0 --- +infty")
printf("exact  = %.18f\n", exact/2)
printf("result = %.18f\n", result)
p w.to_a

p Integration.qagiu(f, xmin)

puts("QAGIL")
result, = f.integration_qagil(0.0, 0.0, 1e-7, 1000, w)
puts("exp(-x*x), x = -infty --- 0")
printf("exact  = %.18f\n", exact/2)
printf("result = %.18f\n\n", result)

f455 = Function.alloc { |x|
  log(x)/(1.0 + 100.0*x*x)
}

exp_result = -3.616892186127022568E-01
exp_abserr = 3.016716913328831851E-06

result = f455.qagiu(0.0, [0.0, 1e-3])
p result
puts("exp_result: #{exp_result}")
puts("exp_abserr: #{exp_abserr}")