Skip to main content Skip to docs navigation

Nonlinear Curve Fitting Calculator

 


 


Calculating!


Copy and paste your data here:

 

Tool Headline

   This nonlinear curve fitting tool uses the Levenberg–Marquardt algorithm to find the best fit of all of the 74 predefined equations built into this website. Updated: 4/21/2024

How to Calculate Nonlinear Regression

Use our online fully automatic nonlinear curve fitting calculator! It has 74 builtin functions, and finds the best ones! Just paste your data into the input field below and press Run to find the best fit for your data.
Sample data has been provided for you to test out this tool.
The first time you load this webpage the tool runs our sample data so you can see how it works.
Just press the Run button to run the tool again.
To run your dataset, replace our demo data with your data and press the run button.

Nonlinear Curve Fitting Calculator Methodology

   This tool is an automatic version of Nonlinear Least Squares Curve Fitting and the four parameter version: Nonlinear Least Squares Curve Fitting - 4 parameter version created by Tom Shattuck, Department of Chemistry, Colby College.

   The Levenberg-Marquardt algorithm that this page uses blends two popular algorithms together to get the best of both. It interpolates between Gauss–Newton and Gradient Descent. In Gradient Descent the algorithm moves in the direction of the steepest gradient of the sum of the squared error by adjusting the parameters. In Gauss-Newton the sum of the squared error is approximated with a quadratic function and the minimum of that quadratic function is solved for. The Levenberg-Marquardt method starts off behaving like Gradient Descent when it is far away from the solution and as it approaches the optimal values for the parameters it begins to act more like the Gauss-Newton method. This behavior gives you the best of both worlds, quick convergence and fine adjustment as you get close.

Nonlinear Curve Fitting Use Cases

   Our O-Ring Groove Design Tool was made using this tool. It helped us find a function to describe how an o-ring's cross-section is reduced as its inner-diameter is stretched. This is where curve fitting really has value. If you have a physical system and have collected data about some element of its reaction to an input then you can use a tool like this to find what mathematical equations best fit the data. Another example of this would be analyzing how coffee brews using a conductivity probe. The conductivity of the coffee as it's brewing goes up both linearly and exponentially. These two separate mathematical functions combine together to match the test data exactly. Discovering this shows how coffee brewing is a combination of brownian motion and diffusion with brownian motion contributing in a linear way to the conductivity and diffusion contributing in an exponential way.

How to Save Time With Curve Fitting Tabulated Data

   Another use for this type of software is converting tabulated data into an equation for use in an excel design sheet. One great example of this is rubber springs with Firestone Marsh Mellow™ Isolators being a leading choice. The way these springs behave is not at all linear. The applied load, height and spring rate are all listed in terms of % compression in a table. Each spring has its own unique table. An enterprising engineer would be wise to convert this tabulated data into functions that could be placed into excel and used in a larger program. The result of this is your engineering department would now be free of having to look up these tables every time they went to design something new, a major time savings.
   There is another reason to curve fit tabulated data and it's to unlock possible hidden physics! Looking at tables that list the torque applied to a bolt in relation to how much clamp force that particular bolt's thread size produces highlights something interesting. It seems that bolt clamp force varies mostly linearly with nominal thread diameter, who knew!

How to Calculate R2 for Nonlinear Regression

   In a nonlinear curve fitting problem, the meaning of R2 breaks down, so it should never be used to choose the best model. Instead the Sum of the Squared Residuals should be used to find the best fit. This is what our tool uses.
That being said, R2 can be calculated by taking 1 and subtracting the Sum of the Squared Residuals (SSR) divided by the Max possible for the Sum of the Squared Residuals.

The way we calculate this is first finding the Max of the Sum of the Squared Residuals (Max_SSR) as simply the y values squared and then added

  Max_SSR=Sum((y_actual)^2)

Next find the SSR by calculating the error at each point, squaring that, and then adding them all up.

  SSR=Sum((Y_actual-Y_estimated)^2)

After that:

   R2 = 1-SSR/Max_SSR.

Again, R2 is only valid for linear fitting, so we suggest that you don't use R2 for Nonlinear regression as that can lead to mixed results when comparing one alternative fit to another.


How to Calculate Nonlinear Regression in Excel

Setting up a nonlinear regression in excel is easy!
It's all about getting your columns right.
First column (A) is your x variable (input)
Second column (B) is your y data (output)
Third column (C) is your curve fitting equation that takes in the x next to it and your coefficients stored in column 6. Be careful to use $ to make those coefficients static/fixed so you can drag the first cell you make down to fill up the whole range.
Fourth column (D) is the square of the error at each point. so (Y_actual-Y_estimated)^2
Fifth column (E) we only use one cell, and that should equal the sum of the squared errors =Sum( column 4 (D) ).
sixth column (F) should store all of your coefficients, each in its own cell, and ideally next to each other.
Lastly use excel's builtin solver to minimize the SSR in column 5 (E) by adjusting the coefficients in column 6 (F).
It's been said that Excel uses Gauss-Newton, Which if true means you should get the same results in excel as you do here.
But hey, Why bother with Excel when you've got this calculator ready to go at a moment's notice!

Nonlinear Curve Fitting Resources

Free Curve Fitting Software

Links to free and proprietary curve fitting software. An excellent list of curve fitting software available.
Gnuplot Wiki A very mature graphing and curve fitting program.
Nonlinear Least Squares Curve Fitting. Our tool was based on this one. created by Tom Shattuck, Department of Chemistry, Colby College.
Nonlinear Least Squares Curve Fitting - 4 parameter version created by Tom Shattuck, Department of Chemistry, Colby College.
SciPy.optimize.curve_fit SciPy is a Free python package that uses Minpack behind the scenes. It's great software.
Minpack Minpack by Netlib is free software written in fortran.
CMinpack Github CMinpack is a C++ rewrite of Minpack
CMinpack Creator CMinpack Homepage
An important quote from the Cminpack creator Frédéric Devernay:
"There is now a very powerful alternative to MINPACK, which is the Ceres Solver. You may want to consider using Ceres for any new project."
Ceres Solver Is a very powerful new solver / optimizer built by Google.

Paid Curve Fitting Software

In order of least expensive to most expensive:
CurveExpert Pro A great tool, it uses python on the backend to calculate a group of functions to help you find the best one.
Sigmaplot Is great for scientists. It has extensive statics builtin.
JMP Is also great for scientists. Also has extensive statics builtin.
Minitab Is also great for scientists. has the most extensive statics builtin.

Curve Fitting References

The Levenberg-Marquardt algorithm for nonlinear least squares curve-fitting problems by Henri P. Gavin

Latest Tools

O-Ring Groove Design Tool

Nonlinear Curve Fitting Calculator


Disclaimer

Recommendations on application design and material selection are based on available technical data and are offered as suggestions only. Each user should make their own tests to determine the suitability for their own particular use. Standards Applied LLC offers no express or implied warranties concerning the form, fit, or function of a product in any application.

Third-party trademarks are the property of their respective owners and are used on this website for informational purposes only. No affiliation with, and no sponsorship or endorsement by, such third-party trademark owners is claimed or implied.