Custom formulas, Fourier series, and registered functions

When no built-in family describes the phenomenon well enough, Curve Fitter lets you declare a function with parameters and physical units, or use periodic models and functions from the Script Library.

Reference interface: GX-TXT DEV112-P011 · Dataset Curve Fit.

Three ways to define a model

Curve Fitter distinguishes between safe formulas interpreted by the numerical engine, the specialized mathematical families already present in the Model selector and the registered functions from GX-TXT scientific scripts. This distinction matters: a formula is not an arbitrary Python program, while a registered function requires an explicit declaration of its parameters and executable source.

The following examples use two synthetic Datasets with independent variable time_s in seconds and voltage_v in volts. In the first case we define a quadratic formula; in the second we use a Fourier series to represent a periodic signal.

Create a physically consistent formula

Consider thirteen synthetic observations of a voltage that rises with a quadratic component. We want to fit the function:

U(t) = a t² + b t + c.

Because U is in volts and t is in seconds, dimensional consistency requires a to be in V/s², b in V/s, and c in V.

Open the c13_quadratic Dataset, select X = Time (s) and Y = Voltage (V), then press Add Dataset curve. In the Fit model and configuration panel choose Model = formula and open Fit → Models and fitting → Safe formula….

In the expression field enter a*x*x+b*x+c. The x variable is the independent physical coordinate selected in the GUI, here time. The mathematical symbol t in our equations corresponds to the editor variable x variable.

Prepare three parameter rows with the following initial values:

Parameter IDUnitInitialRole
aV/s^20.014Quadratic term
bV/s0.060Linear term
cV0.420Intercept

To add the third row use Add parameter. The Lower and Upper fields let you enter optional bounds; the Fixed field holds a coefficient fixed. In this example all three stay free.

Figure 1. A quadratic formula with declared physical parameters. The editor keeps the expression, units, initial values and any bounds separate.

Validate the units before fitting

Press Validate units and formula. The engine checks the mathematical structure and the dimensional compatibility of the terms. A formula that adds quantities that cannot be summed — for example a term in volts and one in seconds without a conversion coefficient — is not a consistent physical relationship.

Figure 2. The message Valid formula states the unit of each coefficient. The dimensional check comes before the numerical estimate.

Validation does not yet show the quality of the fit: it confirms that the declared function is admissible in the expression engine and that the parameters have consistent units. After the check, press Apply formula .

Disable coordinate shifts for the formula

Safe formulas work directly on physical coordinates. If Curve Fitter applies an automatic numerical shift of the axes, you must disable it before the Preview.

Open Fit → Measurements and uncertainty → Input translation / shift positive… and set both mode fields:

FieldValue
Independent axis (geometric X) — modeoff
Dependent axis (geometric Y) — modeoff
Figure 3. Both numerical shifts are disabled so that the function works directly in seconds and volts in the original coordinates.

Press Apply and return to the Viewer. If the translations remained on auto, Curve Fitter would ask you to switch to physical coordinates before calculating the formula; do not read that message as a solver convergence failure.

Calculate the formula Preview

With the three parameters defined and the shifts turned off, press Preview fit. For the thirteen observations the fitted function is, rounded:

U(t) ≈ 0.0140005 t² + 0.0593841 t + 0.4236703, with U in volts and t in seconds.

Figure 4. The fit with a declared formula follows the curvature of the Dataset. The parameters are estimated, not kept at their initial values.

The regression produces RMSE = 0.011253 V and R² = 0.999832. The coefficients and statistics agree, within numerical tolerances, with an independent least-squares regression of the same quadratic function.

Model a periodic signal with a Fourier series

A periodic response may need a form other than a polynomial. A first-order Fourier model uses a constant term and the two fundamental trigonometric functions:

U(t) = C₀ + C cos cos(2πt/T) + C sin sin(2πt/T).

The T period is in seconds. Since sine and cosine are dimensionless, all three coefficients are in V. Higher-order models add harmonics of the fundamental frequency.

Open the synthetic Dataset c13_periodic, with 61 observations between 0 and 15 s; select X = Time (s) and Y = Voltage (V) and press Add Dataset curve. In the Model control choose fourier, set Order N = 1 and Fourier period = 10, then select Output domain = source.

Figure 5. The period sets the fundamental frequency; the order sets how many harmonic terms enter the function.

Interpreting amplitude, phase and offset

Request Preview fit. With the example data the result, rounded, is:

U(t) ≈ 0.380186 + 0.269993 cos(2πt/ 10) + 0.819899 sin(2πt/ 10), with voltages in volts and times in seconds.

Figure 6. The Fourier fundamental describes the synthetic periodic signal; the faster, small-amplitude oscillation remains in the residuals.

The C₀ constant coefficient is the mean level of the model. The sine and cosine components can also be combined into a single sinusoid with amplitude:

A = √(Ccos² + Csin²) ≈ 0.8632 V.

The phase angle follows from the combination of the two coefficients, once the sine or cosine convention is stated. For this reason it is better to keep both coefficients than to report a generic phase value without a convention.

Figure 7. The results tab lists the three coefficients of the series. To interpret them you need to know the order of the trigonometric basis and the unit of the response.

The fit returns RMSE = 0.002819 V and R² = 0.999977. These values describe the agreement with the 61 observations used in the calculation, not a certification of predictive performance outside the domain.

If the period is not known, determine it from the data and physical knowledge before interpreting the coefficients. Raising the order of the series automatically can reduce the residuals, but it can also fit fluctuations that are not harmonics of the phenomenon.

Use registered Python and Octave functions

The Registered Python/Octave model mode lets you use a scientific model saved in the Script Library. This path is separate from the Safe formula editor: here the function is implemented in a registered script and runs as a supervised Job.

To prepare a model, first save the Python or GNU Octave function in the Session Script Library. Then open Fit → Models and fitting → Declare Script Library model… and provide the scientific declaration: script reference, function name, stable model identifier, ordered list of parameters, units, initial values and any bounds.

The declaration also includes the unit of the independent variable, that of the response and the domain allowed for the predictors. A function that accepts only positive values must declare that restriction; the function name and the expected signature, with parameters and predictors, must match the code actually saved.

After the declaration, the Registered Python/Octave model… command lets you select an available function. The Preview is calculated through the framework Job system, while accepting the result remains an explicit operation.

Design these functions to be deterministic, avoiding hidden dependencies on external files or mutable state. The inputs, the meaning of the parameters and the units must be reconstructible so that a saved result can also be interpreted correctly.

Other methods available in Curve Fitter

The Models and fitting section also includes commands for rational or Padé models, implicit equations, complex responses and surface workflows, as well as component and region models. They address different mathematical problems and are not interchangeable alternatives to a simple regression.

A rational model needs attention to poles and to the admissible domain; an implicit equation requires choosing an interpretable branch; a complex response separates real and imaginary components; a surface requires several independent variables and a consistent organization of the data.

Before choosing a specialized family, define which quantities are observed, which are predictors and which residual structure is meaningful. The existence of a menu command does not replace the definition of the scientific problem.

Criteria for a reproducible model

Whether you choose a formula, a Fourier series or a Python/Octave function, a model meant for quantitative use must make explicit the function, the domain, the parameter order, the units, the constraints and the observations used. The Preview helps you examine shape and residuals; physical interpretation also requires checking the underlying assumptions.

Formulas with dimensional coefficients must keep those units through every transformation. For periodic models, recording the period and basis is essential; for registered functions, keep the reference to the source and the scientific declaration. This keeps the results readable and comparable even when you move to different Datasets.