Minpack added for solving non-linear equations and non-linear least-squares
Subject: Minpack added for solving non-linear equations and non-linear least-squares
From: Raymond Toy
Date: Mon, 19 Jan 2009 09:50:43 -0500
>From a suggestion from Robert, I've add minpack to maxima. Minpack
includes software for solving nonlinear equations and nonlinear least
squares problems. Least squares problems use a modified
Levenberg-Marquardt algorithm.
The interface is not complete, but it does work. Here is an example
of how to use it.
(%i1) load(minpack)$
/* Rosenbrock function */
(%i2) f(x1,x2) := [10*(x1-x2^2),1-x1];
(%i3) jacobian(f(x1,x2),[x1,x2]);
(%i4) minpack_lmder1(2,[-1.2,1],lambda([x],f(x[1],x[2])), lambda([x],subst([x1=x[1],x2=x[2]],%o3)),1d-8);
(%o4) [[1.0, 1.0], 0.0, 2]
The result is a list. The first element is the estimated solution,
[1.0, 1.0]. The second element is the norm of the error, and 2 is a
flag returned by the lmder1 routine. (More info available in the
lmder.f file. This will eventually be documented.)
The interface is
minpack_lmder1(m, init, fun, jac, tol)
where
m is the number of equations
init is the initial guess, a vector
f is a function returning a list of each function.
jac is function to evaluate the Jacobian of f.
tol is the tolerance. It should be about sqrt(eps).
I don't think this interface is very nice, and I'm open to others.
It might be better if f could be given as a list of equations instead
of a function taking a vector and returning the list of equations. If
a list is used, then the parameter m isn't needed.
And since this is Maxima, it would be nice if Maxima computed the
Jacobian automatically for us, but we should allow the user to specify
one if necessary. The tolerance should be optional.
Minpack also includes a routine that uses a numerical Jacobian. That
might be useful.
I didn't implement the interface to the routines for solving nonlinear
equations, but that shouldn't be too hard.
Ray