Fitting Data

The Fit

Curve fitting in CFTool uses non-linear optimisation to adjust one or more coefficients so the chosen function best matches the data. The goal is to minimise the total deviation between the data points and the fitted line — the residual error.

01Choosing a function

Whenever possible, start by checking whether a built-in function can represent your data. For some built-in functions CFTool automatically estimates initial parameter values before fitting begins. This is not available for custom functions, so you may need to provide initial guesses manually.

As a general guide:

  • Select a function that matches the expected physical form of the data, or one that approximates it closely.
  • Don’t assume that exponentials always decay to zero, or that sinusoids are centred on zero — add a constant term to allow for offsets if needed.
  • If the fit looks reasonable but the residuals show a pattern, the model may be close but missing an additional term.

02Avoiding over-fitting

Functions with many coefficients — such as high-order polynomials — can often fit the data extremely well. But an excellent visual fit does not necessarily imply physical meaning. Only use such models when you have a theoretical reason to justify them.

03How the fitting process works

Non-linear fitting algorithms work by iteratively adjusting the coefficients to minimise the total squared error between the data and the model.

Occasionally the process can:

  • Converge on a false minimum, where the fit stops before finding the true best solution, or
  • Diverge, with one or more coefficients heading towards infinity and the fit failing entirely.

For example, a sinusoidal fit might stop with the wrong period (a local minimum), and an exponential decay might diverge if the initial guess is far from the true exponent.

04Providing initial coefficient values

If a fit fails or converges incorrectly, supply initial estimates for the most important coefficients in the Fitting Coefficients window. Typical examples:

  • Sinusoidal fit — estimate the amplitude and period by eye from the plot.
  • Exponential decay — estimate the half-life, decay constant and y-intercept.
  • Linear-offset functions — provide a starting value for the offset or slope.

You don’t need to estimate every coefficient — often the most obvious one or two is enough to guide the algorithm towards the correct solution.

If a fit keeps failing. Try adjusting the initial values slightly, or reduce the fitting range to exclude outliers.

05Common fitting problems and solutions

Always inspect the residuals and fit coefficients after every fit — they often tell you more about a model’s suitability than the fit line alone.

Problem Likely cause Remedy
Fit fails to converge Initial guesses too far from the true values Enter approximate starting values for key coefficients
Fit diverges (coefficients → ∞) Wrong function form or unstable initial values Try a different function, or constrain coefficients (Trust Region method)
Fit stops but result looks wrong Algorithm found a false minimum Change initial guesses or slightly alter the fitting range
Residuals show a pattern Model missing a term (e.g. offset or decay constant) Add the missing term, choose a different function, or restrict the x-range
Fit looks perfect but meaningless Too many free parameters (over-fitting) Use a simpler model or reduce the polynomial order
Unrealistic coefficient signs or magnitudes Fit not well constrained Add constraints or provide tighter initial estimates