optimoptions — Create or update solver-specific optimization options for RunMat's supported named solvers.
optimoptions(solver) creates a solver-specific options struct with RunMat defaults. optimoptions(solver, name, value, ...) applies validated name-value overrides, and optimoptions(oldOptions, name, value, ...) copies an existing options struct before applying later values.
Syntax
options = optimoptions(solver)
options = optimoptions(solver, name, value, ...)
options = optimoptions(oldopts, name, value, ...)Inputs
solver- Type
Any- Required
- Yes
- Description
- A supported solver name or its named function handle.
name- Type
StringScalar- Required
- No
- Description
- Option field name.
value- Type
Any- Required
- Variadic
- Description
- Option value(s) and additional name/value pairs.
oldopts- Type
Any- Required
- Yes
- Description
- Existing options struct to update.
value- Type
Any- Required
- Variadic
- Description
- Option value(s), additional name/value pairs, or another options struct.
Returns
options- Type
Any- Description
- Options struct for optimization solvers.
Errors
RunMat:optimoptions:InvalidArgument- When
- Argument grammar does not match supported optimoptions forms.
- Message
optimoptions: invalid argument
RunMat:optimoptions:InvalidSolver- When
- The solver argument is not one of the supported optimization builtins.
- Message
optimoptions: invalid solver
RunMat:optimoptions:InvalidOptionName- When
- An option name is not a text scalar.
- Message
optimoptions: invalid option name
Behavior
FiniteDifferenceStepSize (legacy FinDiffRelStep) accepts a finite strictly positive real floating scalar or vector; a scalar factor expands to every variable. TypicalX must be a finite strictly positive real floating vector with one element per original variable (a scalar for a scalar problem). Omitted or empty controls resolve to sqrt(eps) for forward differences, eps^(1/3) for existing central-difference routes, and unit TypicalX. Forward offsets use sign(x), with sign(0)=1, times the factor and max(abs(x),TypicalX); central offsets omit that sign. Actual representable bound-feasible offsets own the denominators. Nominal underflow uses adjacent representable feasible points; unusable actual offsets or an overflowing central span refuse before probe callbacks. These controls do not add objective calls or bypass existing evaluation budgets. Fully supplied derivative paths leave these operands dormant, without validating or gathering them.
Aliases are solver-aware: StepTolerance maps to TolX, ConstraintTolerance to TolCon, MaxIterations to MaxIter, and MaxFunctionEvaluations to MaxFunEvals. In fminunc, modern OptimalityTolerance and FunctionTolerance remain distinct; legacy TolFun resolves against the effective algorithm, to optimality for quasi-Newton or function change for trust-region. Conflicting supplied legacy/modern values for the same criterion reject. lsqnonlin keeps modern FunctionTolerance and OptimalityTolerance distinct; its legacy TolFun supplies both defaults. Other solver profiles retain their established TolFun aliases. lsqlin keeps its modern optimality and function criteria distinct for reflective execution; quadprog rejects FunctionTolerance.
fminunc permits zero-valued finite step, optimality and function tolerances. lsqlin reflective optimality and function tolerances also permit zero; its interior-point path still requires positive optimality and constraint tolerances. lsqnonlin also accepts zero finite step, function and optimality tolerances, and zero iteration/function limits. Other supported step/function/optimality tolerance domains remain positive. MaxFunEvals and MaxPCGIter require positive exact integers; MaxIter permits zero where the selected solver supports it. PrecondBandWidth accepts a nonnegative exact integer or Inf.
fminunc quasi-Newton HessianApproximation accepts 'bfgs', 'lbfgs' (10 retained updates), or {'lbfgs',m} for positive integer m. Legacy HessUpdate belongs to optimset and also permits 'dfp'/'steepdesc'; optimoptions does not accept that legacy key or those modern update values. ObjectiveLimit is an evaluated-objective threshold, default -1e20, not an unboundedness certificate. UseParallel accepts off/on/auto or logical values: fminunc numerical gradients use real selected native-process/browser-worker batches for on, or for auto/true with an already-open eligible pool. Off/false is serial. On ensures a pool through the existing selected execution configuration or refuses; auto has a documented no-eligible-pool serial fallback, not a callback-error retry. Supplied-gradient execution does not consume it.
fminunc trust-region controls include HessianFcn ([] or 'objective'), HessianMultiplyFcn (one function handle or []), HessPattern (a real numeric or logical square matrix), MaxPCGIter, TolPCG, PrecondBandWidth, and SubproblemAlgorithm ('cg' or 'factorization'). The solver checks variable-dependent dimensions. Hessian/callback carriers are retained without inspecting captured values.
Inspectable trust-region defaults include FunctionTolerance=1e-6, TolPCG=0.1, PrecondBandWidth=0, and SubproblemAlgorithm='cg'. MaxPCGIter is left unset for resolution from the number of variables. Effective trust-region's default evaluation limit is likewise variable-dependent; quasi-Newton retains its 40000 default. Imported nonempty values remain supplied even when equal to another algorithm's default.
Recognized inactive controls remain inspectable in the options struct. The numerical solver applies only controls relevant to its effective algorithm and Hessian/subproblem mode; dormant controls are not gathered or invoked. A trust-region request without a supplied gradient warns and uses quasi-Newton, rather than executing a renamed trust-region loop.
fminunc accepts OutputFcn as one function handle, a cell array of handles, or []. Its observers receive (x, optimValues, state) at init, accepted iterates, and done; true logical stop flags terminate with exitflag -1. Captures are retained without numeric readback. fsolve accepts SpecifyObjectiveGradient=true and requires the callback to return [F,J].
linprog accepts MaxIterations/MaxIter and Display controls for its sparse interior-point algorithm. MATLAB algorithm selections, OutputFcn, and problem-struct form are not implemented; unsupported options are rejected rather than ignored.
The solver selector accepts a supported scalar name or its named function handle, including optimoptions(@simulannealbnd,...). Solver handles select the typed option profile; they are not invoked to manufacture defaults.
The simulannealbnd profile owns AcceptanceFcn,AnnealingFcn,DataType,TemperatureFcn, InitialTemperature,ReannealInterval,HybridInterval,PlotInterval and its documented limits/observers. MaxIterations defaults to Inf; variable-dependent count defaults resolve against the actual decision domain. See simulannealbnd for full contracts.
Unknown options are rejected so solver configuration mistakes fail before the solver starts.
RunMat implements a compatibility subset for its optimization solvers and currently returns a struct rather than MATLAB's solver-options object class.
Native integer option values are independently gated RunMat extensions because documented numeric options use floating classes.
Integer tolerances must be exactly representable before normalization to double. Integer iteration and evaluation limits are parsed as exact structural counts, and accepted 0/1 flag values become logical fields.
Supported named solvers are coneprog, quadprog, lsqlin, linprog, intlinprog, fminbnd, fminunc, fmincon, fseminf, particleswarm, fminimax, fgoalattain, fzero, fsolve, lsqcurvefit, and lsqnonlin. The returned RunMat struct can be passed directly to these solvers.
particleswarm has a genuine adaptive-neighborhood population profile, not a local-optimizer alias. Public MaxIterations, SwarmSize, scalar/vector InitialSwarmSpan, actual InitialPoints/Fval reuse, inertia/neighborhood/velocity controls, duration/second time limits, two-argument observers and real pswplotbestf are supported. UseVectorized has precedence over UseParallel; dormant worker controls are not materialized by the solver. HybridFcn retains the actual selected local target and runs only after relative-change convergence. See particleswarm for all defaults, output shapes, flags and execution boundaries.
fseminf has a distinct typed semi-infinite profile: adaptive interpolation, inner working-set controls MaxSQPIter/TolConSQP, absolute derivative step bounds DiffMinChange/DiffMaxChange, relative line bounds/duration, Diagnostics, FunValCheck, detailed Display forms and real output/plot observers. Legacy TolFun supplies both its function and optimality roles; the defaults remain separate. It permits zero nonnegative tolerances, iteration limits and function-evaluation limits. Algorithm, UseParallel and SpecifyConstraintGradient are not accepted placeholders; see fseminf for complete defaults and ranges.
intlinprog has its own typed option profile: AbsoluteGapTolerance, RelativeGapTolerance, ConstraintTolerance (stored as TolCon), Display, MaxFeasiblePoints, MaxNodes, MaxTime and ObjectiveCutOff. Zero gap/time limits are valid, node/feasible-point counts are positive, and MaxFeasiblePoints, MaxTime and ObjectiveCutOff accept Inf. OutputFcn and PlotFcn accept handles, cells of callbacks, their respective predefined savemilpsolutions/optimplotmilp name, or [] for no observer. Callbacks receive the MILP-specific (x,optimValues,state) event contract and may request a logical true stop; they are not continuous-solver gradient callbacks. No Algorithm option is supplied. See intlinprog for domain constraints and exact option ranges and defaults.
Option names are case-insensitive and use canonical fields TolX, TolFun, TolCon, MaxIter, MaxFunEvals, Display, Algorithm, SpecifyObjectiveGradient, and OutputFcn where accepted by the selected solver. Defaults, aliases, and validation are solver-specific; GradObj aliases SpecifyObjectiveGradient.
quadprog consumes Algorithm='interior-point-convex' (default) or 'active-set', TolFun/OptimalityTolerance, TolCon/ConstraintTolerance, MaxIter/MaxIterations and Display. Active-set additionally consumes StepTolerance, ObjectiveLimit and MaxTime; its default MaxIterations is [] until dimensions resolve 10*(variables + stored linear/bound rows). Explicit iteration counts are preserved. Display defaults to final. Trust-region-reflective and unrelated controls are not aliases.
Display accepts off (also none), iter, and final; fminbnd and fminunc additionally accept notify. Only fminbnd defaults to notify; fminunc defaults to off.
coneprog accepts interior-point and interior-point-convex. The nonlinear least-squares solvers accept levenberg-marquardt and trust-region-reflective; the latter configures RunMat's projected Levenberg-Marquardt implementation rather than selecting a separate reflective algorithm. fminunc accepts quasi-newton, bfgs, and genuine trust-region. SpecifyObjectiveGradient accepts logical/0-or-1 values and on/off spellings.
In RunMat extension mode, accepted native integer MaxIter and MaxFunEvals values retain their exact native integer class in the returned struct, including scalar integer arrays normalized to native scalars. Counts are checked against the platform size range and each solver's nonnegative-iteration or positive-evaluation domain before publication; defaults and ordinary floating inputs remain double. This is RunMat count/publication behavior, not a claim of MATLAB integer-overload parity.
Execution
Options are host metadata; no provider kernel, elementwise fusion, reduction fusion, or GPU precision is claimed. Authenticated automatic controls gather transparently; explicit gpuArray controls require the RunMat extension and unproven placement requires explicit gather. Policy and provider authority come from the original invocation, not an unrelated ambient session.
The builder accepts a solver name or options struct followed by later structs and validated name/value pairs; no fixed argument limit is declared by the metadata builder. Numeric constants remain host metadata; no device constant buffer or shader ABI is promised.
Examples
Supply a quadratic Hessian to trust-region
opts = optimoptions('fminunc','Algorithm','trust-region','SpecifyObjectiveGradient',true,'HessianFcn','objective','Display','off');
[x,fval] = fminunc(@quadratic,[0;0],opts)
function [f,g,H] = quadratic(x)
r = x-[2;-1];
f = sum(r.^2);
g = 2*r;
H = 2*eye(2);
endExpected output:
x =
2
-1
fval =
0Construct coneprog options
opts = optimoptions("coneprog", "TolFun", 1e-8, "Display", "off");
soc = secondordercone(eye(2), [0; 0], [0; 0], -1);
x = coneprog([-1; 0], soc, [1 0], 0.75, [], [], [], [], opts)Expected output:
x =
0.7500
0Construct fminbnd options
opts = optimoptions("fminbnd", "TolX", 1e-10, "Display", "off");
x = fminbnd(@cos, 0, pi, opts)Expected output:
x =
3.1416Construct fzero options
opts = optimoptions("fzero", "TolX", 1e-10, "Display", "off");
x = fzero(@sin, [3 4], opts)Expected output:
x =
3.1416Construct fsolve options
opts = optimoptions("fsolve", "TolX", 1e-8, "TolFun", 1e-8, "Display", "off");
x = fsolve(@sin, 3, opts)Expected output:
x =
3.1416Construct lsqcurvefit options
opts = optimoptions("lsqcurvefit", "StepTolerance", 1e-8, "Algorithm", "levenberg-marquardt");
p = lsqcurvefit(@(p,x) p(1).*x + p(2), [0; 0], [0 1 2], [1 3 5], [], [], opts)Expected output:
p =
2.0000
1.0000Construct lsqnonlin options
opts = optimoptions("lsqnonlin", "FunctionTolerance", 1e-8, "Algorithm", "levenberg-marquardt");
x = lsqnonlin(@(x) [x(1)-2; x(2)-3], [0; 0], [], [], opts)Expected output:
x =
2.0000
3.0000Update an existing options struct
base = optimoptions("fsolve", "TolX", 1e-6);
opts = optimoptions(base, "TolX", 1e-9, "MaxIter", 100);
x = fsolve(@sin, 3, opts)Expected output:
x =
3.1416Create options for a nonlinear solver
opts = optimoptions("fsolve", "TolX", 1e-8, "Display", "off")Expected output:
opts is a RunMat options struct for fsolveUsing optimoptions with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how optimoptions changes the result.
Run a small optimoptions example, explain the result, then change one input and compare the output.
FAQ
How is this different from optimset?⌄
optimoptions starts from solver-specific defaults and validates option names and values immediately. optimset is a looser compatibility helper that preserves unknown fields.
Does optimoptions run on the GPU?⌄
No. Options are host metadata. Automatically resident scalar values gather at the runtime boundary; explicit gpuArray option values require the separately gated RunMat extension. Known invalid metadata is rejected before provider work.
Can I pass optimoptions output to existing solvers?⌄
Yes. The supported named solvers consume their admitted canonical fields; optimoptions validates the selected solver's subset.
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 · fminbnd · 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 · 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 optimoptions is executed, line by line, in Rust.
- View the source for optimoptions 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.