Skip to content

Commit 3102be7

Browse files
authored
Merge pull request #100 from ludvigak/qawf-ex
QAWF quadrature example
2 parents 28d38d0 + 20f80bc commit 3102be7

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

examples/Quadrature.jl

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import GSL
22

3+
## CQUAD
4+
println("CQUAD")
5+
36
f = x -> x^1.5
47

58
ws_size = 100 # Sufficient for most func, according to docs
@@ -16,7 +19,7 @@ abserr = Cdouble[0]
1619
nevals = Csize_t[0]
1720
GSL.integration_cquad(ff, a, b, 1e-10, 1e-10, ws, result, abserr, nevals)
1821

19-
exact = 1/2.5
22+
@show exact = 1/2.5
2023
@show result[]
2124
@show abserr[]
2225
@show Int(nevals[])
@@ -25,3 +28,44 @@ exact = 1/2.5
2528
@assert abs(result[] - exact) < abserr[]
2629

2730
GSL.integration_cquad_workspace_free(ws)
31+
32+
## QAWF
33+
println("QAWF")
34+
35+
f2 = x -> 1/x
36+
37+
# Wrap function
38+
ff2 = GSL.@gsl_function(f2)
39+
40+
# Input params
41+
a = 1.3
42+
epsabs = 1e-8
43+
limit = 100
44+
45+
# Workspaces
46+
workspace = GSL.integration_workspace_alloc(limit)
47+
cycle_workspace = GSL.integration_workspace_alloc(limit)
48+
49+
# QAWO setup
50+
omega = 1
51+
L = 0 # Any value goes
52+
sine = GSL.GSL_INTEG_COSINE
53+
n = 100
54+
wf = GSL.integration_qawo_table_alloc(omega, L, sine, n)
55+
56+
# Outputs
57+
result = Cdouble[0]
58+
abserr = Cdouble[0]
59+
60+
GSL.integration_qawf(ff2, a, epsabs, limit, workspace, cycle_workspace, wf, result, abserr)
61+
62+
GSL.integration_workspace_free(workspace)
63+
GSL.integration_workspace_free(cycle_workspace)
64+
GSL.integration_qawo_table_free(wf)
65+
66+
# int(cos(x)/x, a, inf) = -CosIntegral(a)
67+
@show exact = -GSL.sf_Ci(a)
68+
@show result[]
69+
@show abserr[]
70+
@show result[]-exact
71+
@assert abs(result[]-exact) < abserr[]

0 commit comments

Comments
 (0)