Curve Fitting Calculator
The best straight line, polynomial, exponential, power or logarithmic fit to your data, by least squares.
Results
What this tool does
Fitting a curve asks a different question from interpolating one. Interpolation insists on passing through every point; fitting accepts that measurements carry noise and looks for the underlying shape that comes closest to all of them at once. This page solves the least-squares equations directly for five standard models and reports the R², the residual error and a prediction at any point you like. It also warns about the thing that catches everyone: a higher polynomial degree always fits better, right up to the point where it stops meaning anything.
Formula
min Σ(y − ŷ)² ⟹ XᵀX β = Xᵀy · y = a e^(bx) ⟹ ln y = ln a + b x
Variables
| Symbol | Meaning | Unit |
|---|---|---|
x_values | The x values, one per line or separated by commas | — |
y_values | The y values, in the same order | — |
model | Shape to fit | — |
degree | Degree of the polynomial | — |
at | Predict y when x is | — |
MD | The fitted equation | — |
R2 | Of the variation the line explains | % |
PD | What it predicts there | — |
TB | Power of x · its coefficient | — |
RM | Typical size of the misses | — |
SE | Squared misses added up | — |
NP | Points | — |
Worked example
- The x values, one per line or separated by commas0, 1, 2, 3, 4
- The y values, in the same order1, 2, 5, 10, 17
- Shape to fitpoly
- Degree of the polynomial2
- Predict y when x is5
- The fitted equationy = x^2 + 1
- Of the variation the line explains100.0000 %
- What it predicts there26.00000000
- Power of x · its coefficient0 1 1 0 2 1
- Typical size of the misses0.00000000
- Squared misses added up0.00000000
- Points5
Limitations
- The result is an estimate based only on the values you type. Real situations often include factors this calculator does not know about.
- Standard deviation and variance are calculated for a sample (dividing by n − 1). For a full population, divide by n instead.
Frequently asked questions
Does a higher R² mean a better model?
Not on its own, and this is the trap. Raising the polynomial degree can only ever increase R², because a more flexible curve can always get closer to the points — with as many coefficients as data points it will pass through every one and report a perfect fit while describing nothing at all. That is overfitting, and it shows up the moment you try to predict something new. Prefer the simplest model whose residuals look like scatter rather than pattern, and be suspicious of a degree above three unless you have a reason to expect one.
How are the exponential and power fits done?
By taking logarithms until the model becomes a straight line, fitting that line, and transforming back — which is the standard approach and worth knowing about, because it changes what is being minimised. Least squares on the logarithms gives equal weight to equal relative errors, not equal absolute ones, so small values count as much as large ones. That is usually what you want for growth data and occasionally not. The R² shown is measured on the original scale, not the logged one, so it means what you expect it to mean.