Curve fitting in CFTool uses non-linear optimisation to adjust one or more coefficients so that 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.
Choosing 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 the fitting process begins.
This feature 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.
- Do not assume that functions like exponentials always decay to zero, or that sinusoids are centred around 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.
Avoiding over-fitting
Functions with many coefficients — such as high-order polynomials — can often fit the data extremely well.
However, an excellent visual fit does not necessarily imply physical meaning.
Only use such models when you have a theoretical reason to justify them.
How 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.
- An exponential decay might diverge if the initial guess is far from the true exponent.
Providing 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 the y-intercept.
- Linear-offset functions: provide a starting value for the offset or slope.
You do not need to estimate every coefficient — often, entering the most obvious one or two is enough to guide the algorithm towards the correct solution.
Tip: If a fit fails repeatedly, try adjusting the initial values slightly or reducing the fitting range to exclude outliers.
Common fitting problems and solutions
Always inspect the residuals and fit coefficients after every fit — they often tell you more about the model’s suitability than the fit line alone.
Typical issues and how to resolve them
| 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 → infinity) | Wrong function form or unstable initial values | Try 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 fitting range |
| Residuals show pattern | Model missing a term (e.g. offset or decay constant) | Add missing term, choose a different function or possibly restrict the x-range. |
| Fit looks perfect but meaningless | Too many free parameters (over-fitting) | Use simpler model or reduce polynomial order |
| Unrealistic coefficient signs or magnitudes | Fit not well constrained | Add constraints or provide tighter initial estimates |