fminbnd — Find bounded scalar minima with Brent's method in MATLAB and RunMat.
x = fminbnd(fun, x1, x2) searches the closed interval [x1, x2] for a local minimum of scalar function fun using Brent's method. The documented compatibility contract uses binary64 bounds. Optional outputs return the minimum value, exit flag, and diagnostics.
Syntax
fminbnd(fun, x1, x2)
fminbnd(fun, x1, x2, options)
x = fminbnd(fun, x1, x2)
x = fminbnd(fun, x1, x2, options)
[x, fval] = fminbnd(fun, x1, x2)
[x, fval] = fminbnd(fun, x1, x2, options)All supported fminbnd forms
fminbnd(fun, x1, x2)
fminbnd(fun, x1, x2, options)
x = fminbnd(fun, x1, x2)
x = fminbnd(fun, x1, x2, options)
[x, fval] = fminbnd(fun, x1, x2)
[x, fval] = fminbnd(fun, x1, x2, options)
[x, fval, exitflag] = fminbnd(fun, x1, x2)
[x, fval, exitflag] = fminbnd(fun, x1, x2, options)
[x, fval, exitflag, output] = fminbnd(fun, x1, x2)
[x, fval, exitflag, output] = fminbnd(fun, x1, x2, options)Inputs
fun- Type
Any- Required
- Yes
- Description
- Scalar objective callback.
x1- Type
Any- Required
- Yes
- Description
- Lower bound.
x2- Type
Any- Required
- Yes
- Description
- Upper bound.
options- Type
Any- Required
- No
- Description
- Options struct from optimset.
Returns
x- Type
NumericScalar- Description
- Estimated minimizer location.
fval- Type
NumericScalar- Description
- Objective value at x.
exitflag- Type
NumericScalar- Description
- Convergence status code.
output- Type
Any- Description
- Iteration/function-count metadata struct.
Returned values from fminbnd depend on how many outputs the caller requests.
Errors
RunMat:fminbnd:InvalidArgument- When
- Argument grammar/options parsing is invalid.
- Message
fminbnd: invalid argument
RunMat:fminbnd:InvalidInput- When
- Bounds/callback/input scalar semantics are invalid.
- Message
fminbnd: invalid input
RunMat:fminbnd:TooManyOutputs- When
- More than four output arguments are requested.
- Message
fminbnd: too many output arguments
Behavior
The function handle must return a finite real scalar for every sampled point in the interval.
Strict compatibility mode rejects typed-integer or logical bounds and objective values. RunMat extension mode accepts those values when every integer converts exactly to binary64.
Typed-integer option controls are a separately gated RunMat extension. Structural counts such as MaxIter and MaxFunEvals are validated as exact nonnegative integers rather than rounded through floating point.
If x1 > x2, the bounds are inconsistent and exitflag = -2.
If x1 == x2, that point is returned with exitflag = 1.
Options are supplied as a struct, usually built with optimset. TolX, MaxIter, MaxFunEvals, and Display are accepted.
Display may be 'off', 'iter', 'notify' (default; only prints when the solver fails to converge), or 'final'.
exitflag is 1 on convergence within TolX, 0 when the iteration or evaluation budget is exhausted.
The fourth output is a struct with iterations, funcCount, algorithm, and message fields.
A call with no assigned output still runs the solver and its objective callback; it publishes no result value.
Execution
The solver runs on the host and has no provider-native solver kernel or tall-array execution. Authenticated automatic placement can be gathered transparently under either language compatibility mode. Explicit GPU operands and callback results require the RunMat resident-fallback extension; strict MATLAB mode rejects them before provider access. Device operands with unproven placement require an explicit gather. Compatibility, cancellation and provider authority come from the original invocation.
Fusion: not elementwise; not a reduction. The callback solver executes on the host.
Examples
Minimize a quadratic
x = fminbnd(@(x) (x-2).^2, 0, 5)Expected output:
x =
2.0000Capture the function value too
[x, fval] = fminbnd(@(x) (x-3).^2 + 1, 0, 5)Expected output:
x =
3.0000
fval =
1.0000Tighten tolerances
opts = optimset('TolX', 1e-10, 'Display', 'off');
[x, fval, exitflag] = fminbnd(@cos, 0, pi, opts)Expected output:
x =
3.1416
fval =
-1.0000
exitflag =
1Using fminbnd with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how fminbnd changes the result.
Run a small fminbnd example, explain the result, then change one input and compare the output.
FAQ
Does fminbnd support unbounded minimization?⌄
No. fminbnd requires finite scalar bounds. Use fminunc or fminsearch for unconstrained problems.
Can I retrieve the iteration history?⌄
Yes — request the four-output form [x, fval, exitflag, output] = fminbnd(...) to receive a struct with iterations, funcCount, algorithm, and message.
Does fminbnd guarantee a global minimum?⌄
No. Brent's method converges to a local minimum on [x1, x2]. For multi-modal functions, narrow the interval to bracket the desired minimum.
Related Math functions
Optim
acceptancesa · annealingboltz · annealingfast · coneprog · crossoverarithmetic · crossoverheuristic · crossoverintermediate · crossoverlaplace · crossoverscattered · crossoversinglepoint · crossovertwopoint · eqnproblem · EquationProblem.solve · EquationProblem.subsasgn · EquationProblem.subsref · evaluate · fgoalattain · fitscalingprop · fitscalingrank · fitscalingshiftlinear · fitscalingtop · fmincon · fminimax · fminsearch · fminunc · fseminf · fsolve · fzero · ga · gacreationlinearfeasible · gacreationnonlinearfeasible · gacreationsobol · gacreationuniform · gacreationuniformint · gaplotbestf · gaplotbestindiv · gaplotdistance · gaplotexpectation · gaplotgenealogy · gaplotmaxconstr · gaplotrange · gaplotscorediversity · gaplotscores · gaplotselection · gaplotstopping · integerConstraint · integral · intlinprog · linprog · lsqcurvefit · lsqlin · LsqlinWarmStart.subsasgn · LsqlinWarmStart.subsref · lsqnonlin · lsqnonneg · mutationadaptfeasible · mutationgaussian · mutationpositivebasis · mutationpower · mutationuniform · optimexpr · optimget · OptimizationConstraint.evaluate · OptimizationConstraint.subsasgn · OptimizationConstraint.subsref · OptimizationExitflag.double · OptimizationExitflag.eq · OptimizationExitflag.ne · OptimizationExitflag.string · OptimizationExpression.acos · OptimizationExpression.acosh · OptimizationExpression.acot · OptimizationExpression.acoth · OptimizationExpression.acsc · OptimizationExpression.acsch · OptimizationExpression.asec · OptimizationExpression.asech · OptimizationExpression.asin · OptimizationExpression.asinh · OptimizationExpression.atan · OptimizationExpression.atanh · OptimizationExpression.cat · OptimizationExpression.cos · OptimizationExpression.cosh · OptimizationExpression.cot · OptimizationExpression.coth · OptimizationExpression.csc · OptimizationExpression.csch · OptimizationExpression.ctranspose · OptimizationExpression.cumprod · OptimizationExpression.cumsum · OptimizationExpression.diag · OptimizationExpression.diff · OptimizationExpression.dot · OptimizationExpression.eq · OptimizationExpression.evaluate · OptimizationExpression.exp · OptimizationExpression.ge · OptimizationExpression.horzcat · OptimizationExpression.ldivide · OptimizationExpression.le · OptimizationExpression.log · OptimizationExpression.mean · OptimizationExpression.minus · OptimizationExpression.mldivide · OptimizationExpression.mpower · OptimizationExpression.mrdivide · OptimizationExpression.mtimes · OptimizationExpression.norm · OptimizationExpression.plus · OptimizationExpression.power · OptimizationExpression.prod · OptimizationExpression.rdivide · OptimizationExpression.reshape · OptimizationExpression.sec · OptimizationExpression.sech · OptimizationExpression.sin · OptimizationExpression.sinh · OptimizationExpression.sqrt · OptimizationExpression.subsasgn · OptimizationExpression.subsref · OptimizationExpression.sum · OptimizationExpression.tan · OptimizationExpression.tanh · OptimizationExpression.times · OptimizationExpression.trace · OptimizationExpression.transpose · OptimizationExpression.uminus · OptimizationExpression.uplus · OptimizationExpression.vertcat · OptimizationExpression.zeros · OptimizationExpression.zerosLike · OptimizationProblem.solve · OptimizationProblem.subsasgn · OptimizationProblem.subsref · OptimizationVariable.subsasgn · OptimizationVariable.subsref · optimoptions · optimplotconstrviolation · optimplotfirstorderopt · optimplotfunccount · optimplotfval · optimplotfvalconstr · optimplotmilp · optimplotstepsize · optimplotx · optimproblem · optimset · optimvar · optimwarmstart · particleswarm · patternsearch · psplotbestf · psplotbestx · psplotfuncount · psplotmaxconstr · psplotmeshsize · pswcreationuniform · pswplotbestf · quad · quadprog · QuadprogWarmStart.subsasgn · QuadprogWarmStart.subsref · saplotbestf · saplotbestx · saplotf · saplotstopping · saplottemperature · saplotx · savemilpsolutions · secondordercone · selectionremainder · selectionroulette · selectionstochunif · selectiontournament · selectionuniform · simulannealbnd · solve · surrogateopt · surrogateoptplot · temperatureboltz · temperatureexp · temperaturefast
Elementwise
abs · angle · besselj · bsxfun · complex · conj · double · eps · erf · erfcinv · exp · expm1 · flintmax · gamma · gammaln · heaviside · hypot · imag · int16 · int32 · int64 · int8 · intmax · intmin · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · realmax · realmin · realsqrt · rescale · sign · single · sqrt · times · typecast · uint16 · uint32 · uint64 · uint8
Trigonometry
acos · acosd · acosh · acotd · acscd · asecd · asin · asind · asinh · atan · atan2 · atan2d · atand · atanh · cos · cosd · cosh · cospi · deg2rad · pol2cart · rad2deg · sin · sind · sinh · sinpi · tan · tand · tanh
Reduction
all · any · bounds · cummax · cummin · cumprod · cumsum · cumtrapz · diff · gradient · max · maxk · mean · median · min · mink · movmax · movmean · movmedian · movmin · movprod · movstd · movsum · movvar · nnz · prod · rms · std · sum · trapz · var
Structure
bandwidth · isdiag · ishermitian · issymmetric · istril · istriu · symrcm
Signal
blackman · butter · buttord · cheb2ord · conv · conv2 · deconv · downsample · envelope · filter · filtfilt · fir1 · freqz · gauspuls · hamming · hann · hilbert · periodogram · pulstran · pwelch · rectpuls · resample · sawtooth · sinc · spectrogram · square · tripuls · unwrap · upsample · zplane
Factor
chol · decomposition · decomposition.ctranspose · decomposition.mldivide · decomposition.mrdivide · decomposition.mtimes · decomposition.rdivide · decomposition.subsref · decomposition.times · decomposition.uminus · decomposition.uplus · eig · eigs · gmres · ichol · ilu · lu · ordeig · ordqz · ordschur · pcg · qr · qz · rsf2csf · schur · svd
Ops
cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose
Interpolation
griddedInterpolant · griddedInterpolant.subsref · interp1 · interp1q · interp2 · pchip · ppval · spline
Integer Division
Source you can read
Every RunMat function's source is public. Read exactly how fminbnd is executed, line by line, in Rust.
- View the source for fminbnd in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.