Reference: components

Nonlinear function (Fzero)

Updated 3 November 2026 · 2 min read

A nonlinear function is a variable worked out by SepalSolver’s Fzero: at every step, the x between two bounds that makes an expression zero. Use it for a value defined by an equation you can’t rearrange.

  1. 1The expression in x that should be zero.
  2. 2The bounds the answer lies between.

Settings#

SettingWhat it is
FormulaAn expression in x, the unknown, that is zero at the answer. It may use t, stocks, constants and other variables.
Search from, Search toFormulas the answer lies between: numbers, or values from the model, like 1.5 * InitialPressure.

How it finds the answer#

Fzero uses Brent’s method: it starts with a range whose two ends give the expression opposite signs, so a zero must lie between them, and narrows it until it has the root. It does this at every step of the run, each time with the model’s current values.

Ends differ in sign: Fzero finds the rootSame sign: the range widens firstwidened until the ends differ in sign
Left: the expression changes sign between the bounds, and Fzero narrows in on the root. Right: both bounds give the same sign; the range is widened, up to four times, until they differ.

If the two bounds give the same sign, the builder widens the range up to four times before calling Fzero: the low end is halved if it started at or above zero, otherwise moved down by the range’s width, and the high end moved up by its width. If the expression still doesn’t change sign, the run stops with a message naming the variable and the time:

Price at t = 3.25: nothing between 0 and 16000 makes it zero, so the model has no answer there.

That message almost always means one of two things: the inputs are impossible, like an oil field smaller than the oil already produced, or the bounds don’t contain the answer at all.

Choosing bounds#

Use physical limits you know the answer lies between, not guesses. A price is above zero; a pressure is above zero and not far above where it started. Honest bounds keep Fzero fast and stop it finding a root that means nothing, such as a negative price that also happens to balance the equation.

A worked example#

A market’s price is where supply meets demand. Supply rises with the price, 20 units per dollar; demand falls with it, 2 units per customer times e−price/50. With 3,320 customers after two years, the price is the x where

There is no way to solve that for x by rearranging. Fzero finds x = 74.63: supply 1,493 units, demand 6,640 × e−1.4926 = 1,493 units.

In the C##

double Price = Root("Price", t, x => SupplySlope * x - Customers * PerCustomer * Exp(-x / PriceScale), 0, 1000);

Root checks and widens the range, then calls SepalSolver’s Fzero. A data series compared with a nonlinear function gets more from the fit: at each measurement, the model is also worked out with the variable set to what was measured, which is what diagnostic plots like the oil field’s are drawn from.