# [Maxima] Exponential fitting with lsquares

Leo Butler l.butler at ed.ac.uk
Sat May 23 06:42:46 CDT 2009

```
On Sat, 23 May 2009, Jose A. Vallejo wrote:

< I'm trying to make a script for a calculus class. I want to
< introduce exponential fittings, and I use the example of USA
< population growth, defining:

< y=2*10^(-9)*exp(0.01*x), this is the reason for the initial
< guess):
<
< >> mse:lsquares_mse(M,[x,y],y=a*exp(b*x));
< >> lsquares_estimates_approximate(mse,[a,b],initial=[0.0001,1],iprint=[-1,
< >> 0]);

There appears to be a few problems here. Try rebasing your year in mse,
and try using lbfgs directly to compute the lsq estimate:

mse:lsquares_mse(M,[x,y],y=a*exp(b*(x-1900)));
lbfgs(mse,'[a,b],[100,0.01],1e-4,[1,0]);

*************************************************
THE MINIMIZATION TERMINATED WITHOUT DETECTING ERRORS.
IFLAG = 0
(%o18)          [a = 82.41283534143082, b = 0.012431840496229]

------------------------------------------------------------
The problem appears to be that lsquares_estimates_approximate ignores
the initial value passed to it:

lsquares_estimates_approximate(mse,'[a,b],initial=[82,0.01],iprint=[1,3]);
*************************************************
VECTOR X=
1.000000000000000D+00   1.000000000000000D+00
1.313813415094471D+86   1.313813414823674D+88

If you redefine mse so that [1,1] is a reasonable initial value, you
will get an estimate:

mse:subst([a=82*a,b=0.01*b],mse)\$
lsquares_estimates_approximate(mse,'[a,b],iprint=[1,3]);

THE MINIMIZATION TERMINATED WITHOUT DETECTING ERRORS.
IFLAG = 0
[[a = 1.005034579667296, b = 1.243184045872825]]

Leo

(%i35) build_info();

Maxima version: 5.18.1
Maxima build date: 13:24 4/26/2009
host type: i686-pc-linux-gnu
lisp-implementation-type: GNU Common Lisp (GCL)
lisp-implementation-version: GCL 2.6.8

--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

```