fminbnd
Builtin index · Signal processing
result = fminbnd(f, a, b, [tol=1e-8], [max_iter=500])
Input: f, a, b, tol, max_iter · Output: result
What it is
Minimises a function of one number on a closed interval. f: a function (or the string naming a user-defined function) of one number returning a number; a, b: finite numbers with a < b; tol (positive number): the absolute tolerance on the minimiser; max_iter (positive whole number): the cap on evaluations of f. Method: Brent's golden-section search with parabolic interpolation. It never evaluates the ends of the interval, so a minimum at an end is returned as a point within about tol of it. A smooth minimum can only be located to about sqrt(eps) * abs(x) (about 1.5e-8 relative), however small tol is, because f is flat there.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = fminbnd(f, a, b, [tol=1e-8], [max_iter=500]) | f string or numberf: a function (or the string naming a user-defined function) of one number returning a number.a numbera, b: finite numbers with a < b.b numbera, b: finite numbers with a < b.tol number, optional (default 1e-8)tol (positive number): the absolute tolerance on the minimiser.max_iter number, optional (default 500)max_iter (positive whole number): the cap on evaluations of f. | Model —kind "fminbnd"params numberthe minimiser, a numbervalue —f at paramsconverged booleanbooleaniterations numbera numberf —passed through | Returns a Model (kind "fminbnd") with params (the minimiser, a number), value (f at params), converged (boolean) and iterations (a number), the same fields as minimize. Reaching max_iter is not an error: check converged. Errors: a >= b or a non-finite end, a non-positive tol, an f that returns NaN or Inf (the error names the point), and any error raised inside f (passed through). |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
# y'' + y = 0, y(0) = 0, y(pi/2) = 1 (y = sin x), as the system y' = [y1, -y0]
function osc(x, y)
return [y[1], -y[0]]
end function
function ends(ya, yb)
return [ya[0], yb[0] - 1]
end function
b = bvp(osc, ends, linspace(0, pi/2, 11), zeros(2, 11))
print("{b.status} on {b.nodes} nodes") # converged on 41 nodes
print(bvp_eval(b, pi/4)[0] - sin(pi/4)) # -1.83e-09
c = chebdiff(16)
print(max(abs(c.D * exp(c.x) - exp(c.x)))) # 5.8e-14, spectral accuracy
print(integral2((x, y) := 1, -1, 1, (x) := -sqrt(1 - x^2), (x) := sqrt(1 - x^2))) # 3.141593, the unit disc
r = fminbnd((x) := cos(x), 3, 4)
print("{r.params} {r.converged}") # 3.141593 true
converged on 41 nodes -1.834181e-9 5.817569e-14 3.141593 3.141593 true
from signal-processing