﻿ Nonlinear Curvefitting: Lorentz Curve Fitting, Sine Curve Fitting, Damped Sinusoid CurveFitting

Home

# CurvFit (tm): creates algebraic series for fitting ones data. CurvFit (tm) is a nonlinear curve fitting program. Sine, damped Sine, Lorentz, Modified Lorentz, Power (ie Polynomial) and Exponential series are presently available models to match your data. We strongly suggest trying a Lorentz series for data with multiple peaks or valleys. A calculator exists for interpolation &/or extrapolation of given data. CurvFit has proven excellent for hard to fit data. Hard to fit data may take more time -but- it can be done given the right series and parameter values. For start try curve fitting your data with a Lorentz series!

A Lorentz function equals 1 / (1 + a x2). This is a shortened form of the infinite series inverse (1 + Σ ai x2i). For practical purposes the shortened Lorentz function is accurate enough. The Lorentz function equals the derivative of the arctangent.

A Modified Lorentz function equals (1 + x) / (1 + a x2) = (1 + x) * Lorentz function! Use the modified Lorentz when minimizing number of terms in your curve fit series. (Someone suggested that the modified Lorentz is a Bessel function, is it?)

Fitting Sinusoidal data is simplified by finding good initial starting values for given sinusoidal data. In order to do this try our SpectrumSolvers program using a simple spectral estimator (e.g. AutoCorr). A good estimator will calculate key frequencies. Use these key frequency values as initial starting values in CurvFit. Without these good initial frequencies values Curve fitting sinusoidal data can be tough.

Curve fitting is an Inverse Problem in some cases. For example, you might have some Ordinary Differential Equations (ODEs) where you know the solution data points but question some parameters in the ODEs. The target would be your data points and parameter values would be what you are trying to determine. Another example would be determining a electrical circuit parameters when you know the (target) circuit response desired. Curve fit data to model is quick and easy in a Calculus (level) programming language. There are many industry Inverse Problems that exist but are not classified as such.

CurvFit is a increased productivity example do to using Calculus programming ... ie. minutes to solve, days or years to understand solution and what it implies (e.g. wrong model, sampling rate error, etc.). CurvFit helps one learn ...

• Whether math model is good for given data;
• Convergence report tells whether a reasonable solution; and,
• How to select new starting initial parameter values, model, sampling rate error, etc.)

### CurvFit 6.7Source code:

CurvFit was made possible do to a Calculus-level computer language. The source code (fit4user.fc) file is included in order to show the Calculus programming simplicity. CurvFit is a free (4 MB) download.

### CurvFit 6.7Output Plots:

 (Click Any Image To Enlarge) Plot of Error between Data & Curve Both Data & Model Curve on Plot On this page, I will attempt to guide you through the various routines in order to create a 'picture' for you to understand what's going on. First, the code required and then a sample of output summary.

1. Introduce the Find statement that is used to tweak variables until ones objective(s) are met. The variables may have bounds and constraints that restrick where the selected solver may search for an Optimal solution.

! Find statement is key to tweak variables AND obtain an Optimal ! (i.e., Maximum / Minimum) solutions. FIND y0, a, pw50, t0; IN curve; ! variable list of those to tweak! BY AJAX; TO MATCH error ! objective Minimize / Match error variable!

2. This is a sample of code necessary to solve this problem, but hope it gives you an idea what is going on. Variables to tweak (e.g. y0) MUST always be on the rightside of an equal sign; so the solver can change a value when it wants too. Follow y0 variable throughout the code for seeing what is required. Plus, see y0 and other tweaked variables in output section.

model curve include 'fit.inc' errsum = 0.d0 do 20 i = 1, nPoints y = y0: x = time(i): eq = 0.d0 do 10 j = 1, nTerms call equ( j, x, eq) if(modelX .ne. 7) then y = y + eq else y = y + eq / abs( b(j)) endif 10 continue plotErr(i) = (y - data(i)): error(i) = plotErr(i)**2 20 continue end model equ( j, x, eq) include 'fit.inc' anorm = xnorm / ynorm if( modelx .eq. 1) then ! Lorentzian series xj = x - t0(j) eq = a(j) / (1 + (xj / (pw50(j)/2) )**2) else if( modelx .eq. 2) then ! Mod. Lorentzian series ooo endif end ooo

3. The following block shows a sample of output from the AJAX solver. The first column lists the variables being tweaked; some variables are arrays. The next column, INITIAL, shows initial values for variables that gets things rolling. The next columns are the values for that iteration. This problem required 20 iterations to solve for an optimal solution. Solution time was less than 1-second on a 5-year old PC.

--- AJAX SUMMARY, INVOKED AT FIT FOR MODEL CURVE ---- CONVERGENCE CONDITION AFTER 20 ITERATIONS UNKNOWNS NOT CONVERGED CONSTRAINTS UNSATISFIED MAXIMUM ITERATIONS PERFORMED SPECIFIED CRITERIA UNSATISFIED LOOP NUMBER ......... [INITIAL] 1 2 UNKNOWNS y0 0.000000E+00 4.624447E-03 3.646318E-03 A ( 1) -1.000000E-01 -9.761766E-02 -1.436709E-01 A ( 2) 6.000000E-01 7.034542E-01 7.918994E-01 A ( 3) 1.400000E-01 9.029750E-02 4.250931E-02 PW50 ( 1) 8.000000E-01 1.010919E+00 8.739064E-01 PW50 ( 2) 6.000000E-01 5.116907E-01 5.499282E-01 PW50 ( 3) 8.000000E-01 8.376659E-01 8.564557E-01 T0 ( 1) -4.000000E-01 -5.360891E-01 -5.273902E-01 T0 ( 2) 0.000000E+00 1.576114E-02 1.308791E-02 T0 ( 3) 4.000000E-01 3.783130E-01 3.377194E-01 OBJECTIVE ||G|| 1.517197E+00 5.139380E-01 1.589208E-01 ooo LOOP NUMBER ......... [INITIAL] 19 20 UNKNOWNS y0 0.000000E+00 5.504426E-05 5.504427E-05 A ( 1) -1.000000E-01 -1.950214E-01 -1.950214E-01 A ( 2) 6.000000E-01 8.676625E-01 8.676625E-01 A ( 3) 1.400000E-01 -1.361461E-01 -1.361461E-01 PW50 ( 1) 8.000000E-01 8.722189E-01 8.722189E-01 PW50 ( 2) 6.000000E-01 6.854748E-01 6.854748E-01 PW50 ( 3) 8.000000E-01 6.750204E-01 6.750204E-01 T0 ( 1) -4.000000E-01 -5.477047E-01 -5.477047E-01 T0 ( 2) 0.000000E+00 6.123688E-02 6.123688E-02 T0 ( 3) 4.000000E-01 3.833468E-01 3.833468E-01 OBJECTIVE ||G|| 1.517197E+00 5.251907E-06 5.251907E-06 ! always decreasing ^^^ ? ---END OF LOOP SUMMARY

Are you ready to give it a try? First step is to download our free Calculus (Level) Compiler (i.e., FC-Compiler), install it, and run some Demo (example) files. Next, copy another (Demo) file and save it under another name in your 'user' folder. Edit this file with your equations and (math) models, then save it. Next, try executing it and see how it goes. Enjoy!

Last Updated: Nov. 27, 2023
First Published: Oct. 13, 1992
Requirements:Windows + Visual Basic 6.0 RunTime files
Publisher: Optimal Designs Enterprise

 Description (Click to download) Price 1. CurvFit: Fits Lorentz, Sine, Damped Sine, etc. series to data. Learn the power of a Lorentz series to fitting real data! 0
 All prices in US Dollars

### Curve Fitting Problems in Industry:

• Abnormal Heart Beats or EKGs;
• Ebola epidemic in West Africa;
• 1918 influenza pandemic in San Francisco, California;
• Many Biological systems; and,
• many many many more!

<a href=""><img style="float:left; width:100px" src="https://goal-driven.net/image/curvfit-icon.png"/> <strong>Nonlinear Curvefitting</strong> </a>: Lorentz Curve Fitting, Sine Curve Fitting, Damped Sinusoid CurveFitting, etc. Calculus (level) Problem-Solving for Engineers & Scientists