File: calc-nlfit.el.html
This code uses the Levenberg-Marquardt method, as described in
_Numerical Analysis_ by H. R. Schwarz, to fit data to
nonlinear curves. Currently, the only the following curves are
supported:
The logistic S curve, y=a/(1+exp(b*(t-c)))
Here, y is usually interpreted as the population of some
quantity at time t. So we will think of the data as consisting
of quantities q0, q1, ..., qn and their respective times
t0, t1, ..., tn.
The logistic bell curve, y=A*exp(B*(t-C))/(1+exp(B*(t-C)))^2
Note that this is the derivative of the formula for the S curve.
We get A=-a*b, B=b and C=c. Here, y is interpreted as the rate
of growth of a population at time t. So we will think of the
data as consisting of rates p0, p1, ..., pn and their
respective times t0, t1, ..., tn.
The Hubbert Linearization, y/x=A*(1-x/B)
Here, y is thought of as the rate of growth of a population
and x represents the actual population. This is essentially
the differential equation describing the actual population.
The Levenberg-Marquardt method is an iterative process: it takes an initial guess for the parameters and refines them. To get an initial guess for the parameters, we'll use a method described by Luis de Sousa in "Hubbert's Peak Mathematics". The idea is that given quantities Q and the corresponding rates P, they should satisfy P/Q= mQ+a. We can use the parameter a for an approximation for the parameter a in the S curve, and approximations for b and c are found using least squares on the linearization log((a/y)-1) = log(bb) + cc*t of y=a/(1+bb*exp(cc*t)), which is equivalent to the above s curve formula, and then translating it to b and c. From this, we can also get approximations for the bell curve parameters.