Scalar Root Find — Control Systems/Optimization
Control_Systems/Optimization/Scalar_Root_Find · 1 input / 3 output port(s) at insert · exports to Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text
Description#
The block's own DESCRIPTION_HTML, rendered verbatim — the same text the config dialog's info panel and the library navigator show. Fix a wrong sentence in the block's .cpp (R-D9), never here.
Scalar Root Find
Control Systems / Optimization
Solves p(x) = 0 for a polynomial whose coefficients arrive on a
port, inside a bracket [a, b] given in the configuration –
MATLAB's fzero(@(z) polyval(c, z), [a b]), solved again on every
sample:
p(x) = c₀·xL−1 + c₁·xL−2 + … + cL−1, and x is the point in [a, b] where it crosses zero.
The iteration is Dekker's and Brent's: bisection, secant and inverse
quadratic interpolation, each step whichever of the three is safe. It is
fzero's own, so the answer is the same double MATLAB reports.
Ports
- c – the polynomial's coefficients in descending powers, a column [L,1] with L from 1 to 64 – the shape Polynomial Fit emits and Evaluate Fit reads, so a curve fitted every sample can be solved every sample. A row is refused, because the block reads the column entry by entry.
- x – the root, a scalar [1,1], always inside the bracket.
- f(x) – the polynomial AT that point, a scalar [1,1]. Near zero when the solve converged; it is the honest measure of how well.
- exitflag – a scalar [1,1] saying which of the outcomes below produced x.
Exit flag
- 1 – converged: |x − the bracket's remaining half| is within the tolerance.
- 0 – stopped at Maximum Iterations. x is the best point reached.
- −5 – converged to a point where |p| is LARGER than at
both bracket ends, which is what a pole rather than a root looks like.
fzeroreports the same −5. - −6 – p(a) and p(b) have the same sign, so the bracket holds no crossing this sample. x is the end where |p| is smaller and f(x) its value there.
- −3 – p(a) or p(b) is not finite (an infinity or a NaN arrived on c). Same rule for x as −6.
Parameters
- Options – empty (default), or the path of a Solver Options block (
Home/Solver Options), MATLAB’s options argument: for the run, every option it sets replaces this block’s parameter of the same name; one it leaves atdefault, or one this block does not have, changes nothing. - Bracket – the two ends [a b] as a 1×2 row, the
second argument of
fzero. They may be given in either order. A bracket is a configuration and not a port because it states where the answer is being looked for, which is a property of the diagram rather than of the sample. - X Tolerance –
optimset's TolX, positive. The default iseps= 2.220446049250313e−16, which isfzero's own default and asks for all the precision a double has. - Maximum Iterations – how many function evaluations the main
loop may make, 1 to 10000. Reaching it gives exit flag 0.
fzeroitself has NO limit; a generated core needs one, because a loop printed into ten languages must terminate in all of them. The default, 500, is far above what this iteration needs: over 1003 random polynomials the worst case was 74 evaluations and the median 8. - Sampling Time (s) – zero or less inherits the solver's rate; a positive value runs the block at that period.
Code export
All ten targets: Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog and PLC Structured Text, printed from one description of the iteration, so every target does the same arithmetic in the same order as the simulation. The bracket, the tolerance and the iteration limit are baked in at export time; the coefficients are a signal, so nothing about the polynomial is.
The loop is emitted with a fixed trip count – Maximum Iterations + 1 – and a flag that stops the arithmetic once the answer is found, because none of the ten has an unbounded loop a hardware target could also carry. The cost of a large limit is therefore paid in every target whether or not the samples need it.
The three HDL targets carry the iteration in real
arithmetic and quantize only at the ports: simulation-only, not offered
as synthesizable. Q16.16 resolves 1.5×10−5 and this
block's whole business is a difference of two nearly equal numbers below that
scale; a fixed-point root finder would stall at its own quantum.
Simulink bridge
None (Support::None). The Optimization Toolbox ships
no Simulink library at all – measured, not assumed – so there
is no block to map onto and no library path a diagram could name.
fzero is a MATLAB function. The bridge reports this block rather
than dropping it silently, and it therefore has no parity testbench;
code export verification covers it across all ten languages.
Notes
- Algebraic and stateless: the whole solve happens inside one sample and nothing is carried to the next. That also means a bracket that stops holding a crossing does not fall back on the previous answer – it reports −6, and a diagram that must hold the last good root does it with a Switch and a Memory.
- The bracket is not searched for.
fzeroalso accepts a single starting point and hunts outward for a sign change; that search is unbounded, so this block takes the bracket instead and reports −6 when it does not straddle a root. - Cost is bounded and not constant: between 1 and Maximum Iterations polynomial evaluations per sample, each L − 1 multiply-adds.
- Verified against R2026a bit for bit – x, f(x), the exit flag, the iteration count and every intermediate iterate, over 1003 random polynomials and brackets. The source banner carries the measurement.
- No state space. The relation is nonlinear in the coefficients, so the block carries none and model reduction correctly reports it as unmergeable.
Code facts#
| Fact | Value |
|---|---|
| registered type | Control_Systems/Optimization/Scalar_Root_Find |
| family | Control_Systems/Optimization |
| solver environment class | ICoreBlock_0_Control_Systems_1_Optimization_2_Scalar_Root_Find |
| source | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Optimization/Scalar_Root_Find/ICoreBlock_0_Control_Systems_1_Optimization_2_Scalar_Root_Find.cpp |
| header | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Optimization/Scalar_Root_Find/ICoreBlock_0_Control_Systems_1_Optimization_2_Scalar_Root_Find.h |
| default size on canvas | 150 × 90 px |
| ports at insert | 1 in, 3 out |
| code generators implemented | Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text |
Ports#
| # | Direction | Signal type | Description label |
|---|---|---|---|
| 1 | in | ICoreDouble | c |
| 2 | out | ICoreDouble | x |
| 3 | out | ICoreDouble | f(x) |
| 4 | out | ICoreDouble | exitflag |
Ports the constructor creates. A block whose port list changes with its configuration adds or removes ports at load time; the count above is the one a freshly inserted block has.
Configuration variables#
| Config variable | Default | Simulink parameter |
|---|---|---|
Bracket | [-1 1] | — |
X Tolerance | 2.220446049250313e-16 | — |
Maximum Iterations | 500 | — |
Options | — | — |
Every block also carries Sampling Time (s) from ICoreBlockSolverEnvironment: zero or less inherits the solver's rate, a positive value runs the block at that period.
Simulink bridge#
| support | Support::None |
| Simulink path | — |
| port-count rule | PortsParam::None |
SampleTime parameter | yes |
Caveat (shown to the user): the Optimization Toolbox ships no Simulink library at all, so there is no block to map onto and no library path a diagram could name; fzero is a MATLAB function. The block is reported rather than dropped when a model crosses
Catalog contract: src/ICoreBlocks/ICoreCoder/ICoreCommandSystem/SimulinkBridge/ICoreSimulinkBlockCatalog.h
Description vs code#
The lists agree. check_block_descriptions.py finds no disagreement between the description's Ports, Parameters, Code export and Simulink bridge lists and the code's.
The verdict above is
tools/docs/check_block_descriptions.py(P7.1), which compares LISTS. It cannot read a sentence: "stateless" on a block with a state, an initial-value semantic the recursion does not implement, a "not synthesizable" caveat the HDL banner contradicts. That is the agent audit (P7.3) on BLOCK_DESCRIPTION_AUDIT.md, and this tool's green is not a substitute for one.
File banner (developer view)#
The top comment of the block's .cpp — the maths, the realization and the export strategy, addressed to whoever changes it. It must not contradict the description above (P7.5).
Scalar Root Find -- fzero over a polynomial whose coefficients arrive on a wire p(x) = c0*x^(L-1) + c1*x^(L-2) + ... + c(L-1) c is the input signal, descending [x, fval, exitflag] = fzero(@(z) polyval(c, z), [a b])
The bracket, the tolerance and the iteration limit are configuration; the function is the signal. Everything the iteration does is in ICoreScalarSolverSupport -- one transcription of fzero.m used by the live run and printed into all ten exports, so no target can drift from another or from MATLAB.
Measured against R2026a, and not by agreement to a few digits: over 1003 random polynomials (degree 1 to 8, including clustered and repeated roots) with random brackets, the reference reproduces fzero's x, fval and exit flag BIT FOR BIT, its iteration count exactly, and every intermediate iterate bit for bit -- the iterates rebuilt by capping the loop at n evaluations and compared against fzero's own OutputFcn trace. 714 more solves at non-default tolerances (1e-4 to 1e-14) and 80 with a bracket end exactly on the root, both bit-exact.
The three HDL targets carry the iteration in
real: SIMULATION-ONLY, quantized at the ports.
Sample results#
| t | in ICoreDouble-Out-0 | out ICoreDouble-Out-0 | out ICoreDouble-Out-1 | out ICoreDouble-Out-2 |
|---|---|---|---|---|
| 0 | -2 | -1 | -2 | -6 |
| 0.4 | 0.5 | -1 | 0.5 | -6 |
| 0.8 | -2 | -1 | -2 | -6 |
| 1.2 | 0.5 | -1 | 0.5 | -6 |
| 1.6 | -2 | -1 | -2 | -6 |
| 2 | 0.5 | -1 | 0.5 | -6 |
| 2.4 | -2 | -1 | -2 | -6 |
| 2.8 | 0.5 | -1 | 0.5 | -6 |
| 3.2 | -2 | -1 | -2 | -6 |
| 3.6 | 0.5 | -1 | 0.5 | -6 |
| 4 | -2 | -1 | -2 | -6 |
| 4.4 | 0.5 | -1 | 0.5 | -6 |
| 4.8 | -2 | -1 | -2 | -6 |
| 5.2 | 0.5 | -1 | 0.5 | -6 |
Every 4th of 60 samples, from the table stimulus.
The same rig also ran:
| Stimulus | What it is | Output range |
|---|---|---|
impulse | Impulse: one sample of 1 at k = 5, 0 elsewhere (Repeating Sequence Stair) | -1 … -1 |
ramp | Ramp: slope 1 from t = 0 | -1 … -1 |
sine | Sine Wave: amplitude 1, 2 rad/s, no phase, no bias | -1 … -1 |
step | Step: 0 -> 1 at t = 1 s | -1 … -1 |
Plotted: table — Repeating Sequence Stair: [-2 -1 -0.5 0 0.5 1 2 3], one entry per sample
Category static · sample time 0.1 · 60 steps · commit 6b0471a23bd6163d7d7f33f764df08a614c2b6b8 · produced by docsSample --out <folder> --blocks Scalar_Root_Find Scalar_Bounded_Minimization Order_Waveform Order_Track RPM_Frequency_Map RPM_Order_Map --steps 60 · data docs/generated/samples/Control_Systems__Optimization__Scalar_Root_Find.json · the SVG is generated from those numbers by tools/docs/plot_svg.py, so it is a run and not a drawing (R-D10).