Qu

quad

Builtin index · Signal processing

quad(f, a, b, [tol=1e-10], [maxdepth=60])

Input: f, a, b, tol, maxdepth · Output: no output

What it is

Adaptive Gauss-Kronrod (G7K15, QUADPACK's rule and error scaling) integral of f(x) over [a, b]; f takes and returns a number. a or b may be inf / -inf (a change of variable maps the range to a finite one), and a > b gives the negated integral. Endpoint singularities such as 1/sqrt(x) on (0, 1] converge because the nodes never touch the ends and the interval nearest the singularity is bisected repeatedly. Converged when the summed error estimate is at most tol * max(1,

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
quad(f, a, b, [tol=1e-10], [maxdepth=60])
f numberf takes and returns a number.
a —a or b may be inf / -inf (a change of variable maps the range to a finite one), and a > b gives the negated integral.
b —Adaptive Gauss-Kronrod (G7K15, QUADPACK's rule and error scaling) integral of f(x) over [a, b].
tol optional (default 1e-10)Converged when the summed error estimate is at most tol * max(1,.
maxdepth optional (default 60)not documented yet
not documented yetEndpoint singularities such as 1/sqrt(x) on (0, 1] converge because the nodes never touch the ends and the interval nearest the singularity is bisected repeatedly.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

function vdp(t, y)
    return [y[1], 1.0 * (1 - y[0] * y[0]) * y[1] - y[0]]
end function

r = ode45("vdp", [0, 20], [2, 0])
print(r.status)                 # ok

print(r.y[length(r.t) - 1, 0])  # position at t = 20

print(quad((x) := exp(-x * x), -inf, inf))   # 1.7724538509 = sqrt(pi)

output
ok
2.008149
1.772454

from signal-processing

How it works

and general minimization. Only a user-defined function (by name, the same convention pmap/spawn use) can be the target of any of these — not a builtin. fzero(f, a, b, [tol=1e-10], [max_iter=100]) — Brent's method: robust root finding (guaranteed convergence given a bracket [a,b] where f changes sign), no derivative needed. The "something better than plain bisection" choice.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.