Solve: Error in PROGN [or a callee]: Bind stack overflow.
Subject: Solve: Error in PROGN [or a callee]: Bind stack overflow.
From: Julian Andres Klode
Date: Tue, 23 Nov 2010 17:53:31 +0100
On Di, 2010-11-23 at 15:29 +0000, Leo Butler wrote:
>
> On Tue, 23 Nov 2010, Julian Andres Klode wrote:
>
> < When trying to run the code below, I get
> < Error in PROGN [or a callee]: Bind stack overflow.
> <
> < The function preg() is doing regression, returning a term approximating
> < the points P. The term is based on 'term', with the variables in 'vars'
> < being replaced. When running on a term a^x, solve() results in a bind
> < stack overflow; for a * x it works perfectly.
> <
> < Hope you can help, as I need this function to work.
> <
> < -- Maxima version information:
> < Maxima version: 5.22.1
> < Maxima build date: 1:16 11/6/2010
> < Host type: x86_64-unknown-linux-gnu
> < Lisp implementation type: GNU Common Lisp (GCL)
> < Lisp implementation version: GCL 2.6.7
> <
> < -- Code:
> < preg(P, term, vars) := block([eqns, g, res, ratprint: false],
> < g : sum((P[i][2] - subst(P[i][1], x, term))^2, i, 1, length(P)),
> < eqns : makelist(diff(g,vars[i]), i, 1, length(vars)),
> < subst(solve(eqns, vars)[1], term)
> < )$
> <
> < P : [[1650, 0.545], [1750, 0.728], [1800, 0.906],
> < [1850, 1.171], [1900, 1.608], [1950, 2.517]]$
> <
> < preg(P, a ^ x * b, [a, b]);
>
> Is there a reason you are trying to find an exact solution, when
> your input data are floats? The lbfgs package provides an iterative
> floating-point solver. The lsquares package also provides an interface
> that you can use without needing to write lots of code. Both are
> documented in the manual.
> Leo
I just implemented a straight-forward solution to the problem. I did not
find the packages, probably because I only searched for solve, and
completely ignored the possibility to look for square-related stuff.
I also noticed that the solution I am looking for is a^x*b, not a^x+b. I
then used lsquares_estimates() and everything works, although the
performance seems to be very slow, at least compared to what I recall to
have seen from MuPad users.
In case you are interested, my final function is:
preg2(P, term, vars) := block([p, vals, res],
p: apply(matrix, P),
vals: lsquares_estimates(p, ['x,'y], 'y=term, vars),
res : subst(vals[1], term),
if (pregplot) then
wxplot2d([res, ['discrete, P]], ['x, P[1][1]-5, P[length(P)][1]+5],
['legend, "N?herungsfunktion", "Punkte"],
['style, 'lines, 'points]),
float(res)
);
Which takes a list of points (P), a term with x (term), and a list of
variables (vars). It supports printing of the points and the created
function if pregplot is true. It's just a bit more simplified interface
for my use cases now (which are: find a function and plot it).
Thanks for your help!
--
Julian Andres Klode - Debian Developer, Ubuntu Member
See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/.