Home / Science / Physics / General physics lab helpers / Curve fitterTool #976

Curve fitter: linear and nonlinear least squares with residuals, chi-square and parameter uncertainties

Fit a straight line, polynomial, exponential, power law, Gaussian, sine wave or your own formula to x, y data, weighted by the y uncertainties if you have them, and get each parameter with its uncertainty and 95 % interval, chi-square, reduced chi-square and p-value, residuals and correlations.

Keep it one tap away for everyday use.

Bookmark Curve fitter?

Press Ctrl + D now. Your browser opens its own bookmark box, where you choose the name and folder.

  1. Data
  2. Model
  3. Residuals
  4. χ²
Nothing is uploadedWorks offline once open

Data

Model

Formula: any expression in x with named parameters, such as A*exp(-x/tau) + c (functions exp, ln, log, sqrt, sin, cos, tan, abs; pi). Starting values: name = value, separated by commas; nonlinear fits need sensible ones, and the built-in models guess them from the data. With an uncertainty column the fit is weighted by 1/σ² and the parameter uncertainties are taken as absolute; tick the box if your σ values are only relative. The example (counts against time) is made up.

Fit

Parameter correlations

Next steps: carry these parameters and their uncertainties into the uncertainty propagation calculator, or draw a publication figure with the plot maker. Least squares assumes the x values are exact and the y errors are independent and roughly normal.

Download

What it does

Fitting a curve to measurements is the heart of most lab reports: a straight line through a calibration, an exponential through a decay, a Gaussian through a peak. This fitter finds the parameters that make the curve pass as close as possible to your points (least squares), tells you how well each parameter is known, and checks whether the curve actually describes the data.

It works for straight lines and polynomials (linear models) and for nonlinear models such as exponentials, power laws, Gaussian peaks and sine waves, or any formula you type, using the Levenberg-Marquardt method. If you have an uncertainty for each y value, the fit gives more weight to the better-measured points and you get a chi-square test of the fit.

How to use it

  1. Paste your data (columns x, y and, if you have it, σy), or open a CSV, TSV, text or Excel file. Pick the columns if there are more.
  2. Choose a model, or “My own formula” and type it, for example A*exp(-x/tau) + B. Every name other than x is a parameter.
  3. The built-in models guess starting values from the data. For your own formula, give them as A = 100, tau = 5, B = 10; a nonlinear fit can fail or find the wrong minimum from a poor start.
  4. Read the parameter table, the fit statistics, the plot with the fitted curve and the residual plot.
  5. Download the fitted values and residuals as CSV, or the report as an image, PDF or Word file.

Reading the results

  • Std. uncertainty is the one-standard-deviation uncertainty of each parameter; the 95 % interval uses Student’s t for your degrees of freedom. The Written column rounds each pair the way a report would.
  • χ² adds up (residual ÷ σ)². With honest uncertainties and the right model, the reduced χ² (χ² ÷ degrees of freedom) is about 1. Much larger means the model misses something or the σ are too small; much smaller means the σ are probably too large. The p-value puts a number on it.
  • Residuals should scatter evenly about zero. A curve or trend in them means the model is wrong, even if R² is high.
  • Correlations near ±1 mean two parameters trade off against each other and are poorly separated by your data.
  • Without σ, the uncertainties come from the scatter of the residuals. With σ they are absolute; tick scale by √(χ²/dof) if your σ are only relative (this matches most spreadsheet and curve-fitting programs).

Worked example

The example is a made-up count rate falling with time, with σ = √counts. Fitting exponential decay with offset, y = a·exp(−x/t) + c, gives t = 4.56 ± 0.52 s, a = 109.5 ± 7.3 and c = 10.9 ± 2.1, with χ²/dof = 0.764 (p = 0.74): consistent with the uncertainties. A straight line gives χ²/dof = 5.90 with p = 3.3 × 10⁻¹⁵, clearly the wrong model, even though its R² is not far off. Removing the weights (choose “None” for the uncertainty) gives t = 4.83 ± 0.55 with R² = 0.9651.

FAQ

Which model should I choose? The one your physics predicts. Comparing models by AIC (lower is better) helps when you are unsure, but more parameters always fit a little better.

My fit fails to converge. Give better starting values, check the units, and try a simpler model first.

Do my data leave this page? No, the fit runs entirely in your browser.

Where the numbers come from

  • Weighted least squares, Levenberg-Marquardt, parameter covariance, chi-square goodness of fit: standard methods, for example Bevington, P. R. and Robinson, D. K. (2003), Data Reduction and Error Analysis for the Physical Sciences; Press, W. H. et al., Numerical Recipes (incomplete gamma function).
  • Checked against scipy.optimize.curve_fit (absolute_sigma=True for weighted fits) and scipy.stats.chi2.sf on the example data for every built-in model, written for the tests; parameters agree to 1e-8 and uncertainties to 1e-7.
  • The example data (counts against time) are made up.

Standard scientific values, such as constants, atomic weights and melting points, are facts found in every textbook; we name where ours were checked. If you are an author or publisher and want a value, a credit or a table changed or removed, tell us and we will act quickly.

Last updated 2026-11-09.

Related tools

Optical tweezers calibration #974 Paste a trapped bead's position record and get the trap stiffness two ways: from the corner frequency of a Lorentzian fitted to the power spectrum (with the aliasing correction for sampled data and Faxén's correction near a surface), and from equipartition. Works in volts too, giving the detector's nm per volt. Uncertainty propagation calculator #25 Type your formula and your measurements with their uncertainties, or paste repeated readings. Get the result with its uncertainty, which input matters most, and a Monte Carlo check. Significant figures checker #975 Count the significant figures in any number and see which digits count, round to significant figures or decimal places (half up or half to even, with exact decimal arithmetic), write a value and its uncertainty the way lab reports expect, apply the sum and product rules, and check a whole table of results at once. Physical constants #977 Look up the fundamental physical constants (speed of light, Planck, Boltzmann, Avogadro, electron and proton masses, fine-structure constant and 60 more) as recommended by CODATA in 2022 and 2018, with their units, standard uncertainties and one-tap copy, all working offline. Oscilloscope CSV viewer #979 Open the CSV your oscilloscope saves and get the measurements a scope makes: frequency and period, 10-90 % rise and fall time, top, base, peak to peak, RMS, duty cycle, and the delay and phase between two channels, with a plot of every channel and a zoom on the first edge. Publication plot maker #27 Paste columns or open a CSV or Excel file and get a clean scientific figure with error bars, sized for a journal column. Download vector SVG or PDF, or PNG at 300 or 600 dpi. Your data stays in your browser.