-
Notifications
You must be signed in to change notification settings - Fork 15
/
numerical.jl
37 lines (25 loc) · 1.06 KB
/
numerical.jl
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
import QuadGK: quadgk
### NIntegrate
@mkapprule NIntegrate
@sjdoc NIntegrate """
NIntegrate( expr, [x,x0,xf])
Integrate the Symata expression `expr` numerically between `x0` and `xf`.
NIntegrate( expr , [x,x0,x1,...,xf])
Specify singular points between the limitx `x0` and `xf`.
NIntegrate( f, [x0,xf])
NIntegrate( f , [x0,x1,...,xf])
Integrate the compiled function `f` numerically.
NIntegrate returns `[result, err]`.
!!! note
Giving an uncompiled expression is slower than giving a compiled function. But, for
many purposes, the difference in efficiency is not important.
`f = Compile(expr)` compiles `expr` to the function `f`.
"""
quadgklist(f,args) = mxprcf(:List, quadgk(f, map( x -> float(doeval(x)), args)...)...)
@doap function NIntegrate(expr, range::Mxpr{:List})
r = margs(range)
(sym,x0,x1) = length(r) == 3 ? (r...,) : length(r) == 2 ? (:x,r...,) : symerror(range, " is not a valid integration ranges")
f = doeval(expr)
isa(f,Function) && return quadgklist(f,(x0,x1))
quadgklist(wrap_symata(expr,sym), (x0,x1))
end