Generated reference › Nonlinear System Solve — Control Systems/Optimization
kind: generated#block#control-systems-optimization

Nonlinear System Solve — Control Systems/Optimization

F=0

Control_Systems/Optimization/Nonlinear_System_Solve · 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.

Nonlinear System Solve

Control Systems / Optimization

Finds the x that makes n multivariate polynomials vanish together, their coefficients arriving on a port – MATLAB's fsolve at its default algorithm, the trust-region dogleg, solved again on every sample:

Fj(x) = Σt cj,t · x1e(t,1) · … · xne(t,n) = 0,   j = 1 … n

The system is square: as many equations as unknowns, which is the only shape fsolve's dogleg accepts. The exponents e are configuration – they are the system's shape, and shape fixes the loop bounds every export unrolls. The coefficients c are the signal, one column per equation over the same term dictionary, so the surface being rooted can change on every sample while its form does not.

The factory setting is a circle met by a parabola: x₁² + x₂² − 4 = 0 and x₁² − x₂ − 1 = 0 – the four terms [2 0; 0 2; 0 0; 0 1] against coefficients [1; 1; −4; 0; 1; 0; −1; −1] from [1; 1], whose root is (1.5175…, 1.3027…).

Ports

  • c – the term coefficients of every equation, a single column [T·n, 1]: rows (j−1)·T+1 … j·T are equation j's, one per ROW of Term Exponents and in the same order. A row vector, or any other height, is refused – the block reads the column entry by entry, and a matrix port would be flattened one way by MATLAB and the other by Python.
  • x – the root, [n,1], one entry per variable (n = the columns of Term Exponents).
  • F(x) – the equations there, [n,1]. At a root these are zero; when the search stops short they are what it stopped at, which is why the port exists.
  • exitflag – a scalar [1,1], fsolve's own numbers: 1 the first-order measure fell below Optimality Tolerance, 2 the step got too small to matter, 3 the residual stopped changing, −2 it converged to a point that is not a root, −3 the trust region collapsed, 0 a limit below stopped it first.

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 at default, or one this block does not have, changes nothing.
  • Term Exponents – a [T,n] matrix of whole numbers from 0 to 4: row t, column i is the power of xi in term t. T is 1 to 8 terms, n is 1 to 4 variables, and no single term may total more than degree 4. Those three caps are the export's, not the solver's – see Code export.
  • Start Point – x0, fsolve's second argument, a vector of n entries. The search is LOCAL: a square polynomial system generally has several roots, and this parameter chooses which one is reported.
  • Optimality Tolerance – fsolve's OptimalityTolerance (TolFun), positive; default 1e-6. The largest entry of J′F must fall below it, on a step that was accepted.
  • Function Tolerance – FunctionTolerance (TolFunValue), positive; default 1e-6. It does two jobs, both MATLAB's: it is the residual test that ends the search with flag 3, and its square root is the bar a stopped point must clear to be called a root at all – above it the flag becomes −2.
  • Step Tolerance – StepTolerance (TolX), positive; default 1e-6. Its SQUARE is what the relative step is compared against, as trustnleqn does.
  • Maximum Iterations – MaxIterations, 1 to 2000, default 400, which is MATLAB's own.
  • Maximum Function Evaluations – MaxFunctionEvaluations, 0 to 2000. 0 means automatic and resolves to MATLAB's default for this algorithm, 100·n. Whichever limit binds first stops the search and the exit flag is 0.
  • 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 – including the three summation orders below, which are association orders and nothing else.

The exponent pattern is unrolled, for F and for every entry of the Jacobian: a power becomes repeated multiplication, because no target can take a loop bound out of a real array. The body holds two copies of that (one before the loop, one inside it), which is why T, n and the degree are capped where they are – Java refuses a method over 64 KB. The main loop is emitted with a fixed trip count (Maximum Iterations) 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 three HDL targets run the search in simulation-only real arithmetic, quantizing only at the port boundaries: a dogleg step divides and compares across many orders of magnitude, which a Q16.16 datapath does not carry.

Simulink bridge

None (Support::None). The Optimization Toolbox ships no Simulink library at all and fsolve is a MATLAB function, so there is no block to map onto; the bridge reports this block rather than dropping it silently, and it has no parity testbench. Code export verification still covers it across all ten languages.

Notes

  • Stateless: the search restarts from Start Point on every sample, so the answer depends only on the coefficients present at that step, exactly as its four neighbours in this family do.
  • ⚠ The Jacobian used after a REJECTED step is the rejected point's. That is what trustnleqn does – it evaluates F and J together at every trial point and only puts F back when the step is accepted – and it is transcribed rather than corrected, because correcting it is a different solver.
  • ⚠ LOCAL, and a square polynomial system has several roots. A different Start Point gives a different one; that is the method, not a defect.
  • ⚠ A stopped point is not always a root. When the residual is above the square root of Function Tolerance the flag is −2 and F(x) says how far off it is. Every port still carries a number on every sample, which a block must do and fsolve need not.
  • The Gauss-Newton step is an LU factorization with partial pivoting of the Jacobian. An exactly singular Jacobian is not an error: the step falls back to the Cauchy point, which is what MATLAB's non-finite test does with the Inf that \ returns there.

Code facts#

FactValue
registered typeControl_Systems/Optimization/Nonlinear_System_Solve
familyControl_Systems/Optimization
solver environment classICoreBlock_0_Control_Systems_1_Optimization_2_Nonlinear_System_Solve
sourcesrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Optimization/Nonlinear_System_Solve/ICoreBlock_0_Control_Systems_1_Optimization_2_Nonlinear_System_Solve.cpp
headersrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Optimization/Nonlinear_System_Solve/ICoreBlock_0_Control_Systems_1_Optimization_2_Nonlinear_System_Solve.h
default size on canvas180 × 90 px
ports at insert1 in, 3 out
code generators implementedPython, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text

Ports#

#DirectionSignal typeDescription label
1inICoreDoublec
2outICoreDoublex
3outICoreDoubleF(x)
4outICoreDoubleexitflag

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 variableDefaultSimulink parameter
Term Exponents[2 0; 0 2; 0 0; 0 1]—
Start Point[1; 1]—
Optimality Tolerance1e-6—
Function Tolerance1e-6—
Step Tolerance1e-6—
Maximum Iterations400—
Maximum Function Evaluations0—
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.

supportSupport::None
Simulink path—
port-count rulePortsParam::None
SampleTime parameteryes

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; fsolve 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 checker has a blind spot here — it could not resolve something (a grouped port bullet, a computed config name), which is reported and never counted as a pass. A reader has to settle it:

  • B0 every stimulus in the sample errored — cross-checks skipped

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).

Nonlinear System Solve -- fsolve over a SQUARE polynomial system whose coefficients are a wire F_j(x) = sum over terms of c(j,t) * x1^e(t,1) * ... * xn^e(t,n) = 0, j = 1 .. n [x, fval, exitflag] = fsolve(F, x0)

THE OBJECTIVE SEAM IS THE FAMILY'S, ONE DIMENSION WIDER. Scalar Root Find and Scalar Bounded Minimization take a polynomial's coefficient column on a port; Nelder-Mead Search added the EXPONENT PATTERN as configuration so the polynomial could be multivariate. A system needs one thing more -- n of those polynomials -- and it gets them over the SAME term dictionary, so the coefficient port is n columns stacked into one: rows (j-1)*T+1 .. j*T are equation j's. One unrolled evaluation then serves all n equations and, differentiated term by term, the whole Jacobian. Nothing about the system is free: this block solves polynomial systems, and says so.

THE ITERATION IS trustnleqn.m AND dogleg.m (R2026a), TRANSCRIBED. Delta = 1, DeltaMax = 1e10, eta1 = 0.05, eta2 = 0.9, alpha1 = 2.5, alpha2 = 0.25; the Cauchy step, the Gauss-Newton step, the dogleg intersection solved by the stable 1-D quadratic, and testStop's six branches in their order. TypicalX is at its default, so scale is false, the scaling matrix is the identity and every ./scalMat in dogleg.m drops out -- which is why none appears below.

⚠ THE JACOBIAN IS OVERWRITTEN AT EVERY TRIAL POINT, ACCEPTED OR NOT, AND THAT IS NOT A BUG HERE -- IT IS WHAT MATLAB DOES. trustnleqn's 'fungrad' branch is [F,JAC] = feval(eqfcns,x), evaluated at the TRIAL point before the accept/reject test, and nothing puts JAC back when the step is rejected. Fvec and grad are only updated on acceptance. So the iteration after a rejection runs its dogleg on a MISMATCHED pair: F and grad from the accepted point, J from the point that was thrown away. Measured, not read: a debugger stopped inside trustnleqn at the first rejection of a one-variable case reported JAC = -1.6083549248336375, which is the Jacobian at the REJECTED trial point -0.97016, not at the current x = 0.14160. Writing the obvious thing instead -- recompute J only on acceptance -- reproduced fsolve on 91 of 200 random systems; transcribing this reproduces it on 975 of 1000.

⚠ THE SUMMATION ORDER IS PART OF THE ANSWER, AND IT WAS MEASURED. A trust-region iteration turns a last-bit difference into a different accept/reject decision, so A'*b, A*b, norm and x'*x were each probed against R2026a over 6000 random matrices at n = 1..4:

A'*b, x'*x a BINARY TREE split in halves n=3: q0+(q1+q2) n=4: (q0+q1)+(q2+q3) A*b plain LEFT TO RIGHT n=4: ((q0+q1)+q2)+q3 norm(x) sqrt of a TWO-LANE tree n=3: q0+(q1+q2) n=4: (q0+q2)+(q1+q3)

Each of those is exact on all 6000 (dot, axpy and sq below); the obvious left-to-right spelling is exact on 61 %, 100 % and 84 % of them. Putting the three orders in raised the agreement with fsolve from 119 of 200 to 193 of 200 on the same systems. They are association

Sample results#

No stimulus produced a sampled output in this rig — Invalid input size at: ICore Blocks/Home/Nonlinear System Solve. That is a fact about the single-block rig, not a verdict on the block: an offline batch fit, a block whose output only appears at onSolverFinish, or one that needs a driven environment cannot be exercised alone.

Category unsampled · sample time 0.1 · 60 steps · commit cae561964 · produced by docsSample --out <folder> --blocks Nonlinear_System_Solve --steps 60

Sample data: docs/generated/samples/Control_Systems__Optimization__Nonlinear_System_Solve.json