OK, here it is. This is just a simple newton method for two
dimensional systems. I have not tried to study it carefully, but I
was curious about the 'bind stack overflow in some cases, but not
others'
Here is the code
/***************************/
newton2d(expr,var,x0,eps):=
block([u,v,s,numer],
numer:true,
s:matrix([diff(expr[1],var[1]),diff(expr[1],var[2])],
[diff(expr[2],var[1]),diff(expr[2],var[2])]),
u: matrix(x0),
loop, if ( subst(u[1][2],var[2],subst(u[1][1],var[1],expr[1]) )^2
+ subst(u[1][2],var[2],subst(u[1][1],var[1],expr[2]))^2 < eps)
then return([u[1][1],u[1][2]]),
v: subst(u[1][2],var[2],subst(u[1][1],var[1],expr)),
u: u - v
.
subst(u[1][2],var[2],subst(u[1][1],var[1],invert(transpose(s)))),
go(loop) )$
/*****************************/
Notice what happens on the following input. For 'x^2, x^4, x^6' in the
first part of the equation the routine works. For odd powers, 'x^3,
x^5' it fails.
(%i2) newton2d([x^2 - y^2 + sin(y),x + exp(y)], [x,y],[4,1],1e-9);
(%o2) [- 0.69638309339978, - 0.36185529486674]
(%i3) newton2d([x^3 - y^2 + sin(y),x + exp(y)], [x,y],[4,1],1e-9);
Maxima encountered a Lisp error:
Error in PROGN [or a callee]: Bind stack overflow.
Automatically continuing.
To reenable the Lisp debugger set *debugger-hook* to nil.
(%i4) newton2d([x^4 - y^2 + sin(y),x + exp(y)], [x,y],[4,1],1e-9);
(%o4) [- 0.76339215595524, - 0.26998142558939]
(%i26) newton2d([x^5 - y^2 + sin(y),x + exp(y)], [x,y],[4,1],1e-9);
Maxima encountered a Lisp error:
Error in PROGN [or a callee]: Bind stack overflow.
Automatically continuing.
To reenable the Lisp debugger set *debugger-hook* to nil.
(%i28) newton2d([x^6 - y^2 + sin(y),x + exp(y)], [x,y],[4,1],1e-9);
(%o28) [- 0.80238189619342, - 0.2201624673687]
Thanks for any ideas,
-sen
---------------------------------------------------------------------------
| Sheldon E. Newhouse | e-mail: sen1 at math.msu.edu |
| Mathematics Department | |
| Michigan State University | telephone: 517-355-9684 |
| E. Lansing, MI 48824-1027 USA | FAX: 517-432-1562 |
---------------------------------------------------------------------------
On Fri, 6 Apr 2007, Richard Fateman wrote:
> There are a few possible responses to this.
> 1. Maybe your simple procedure does not terminate, and no size stack will
> allow it to complete.
> 2. Maybe the stack allocation in whatever lisp you are using is too small,
> and should be made larger so that your program can complete.
>
> only after these issues are raised would I recommend that you reprogram your
> algorithm (unless it is indeed a very simple algorithm and is even simple
> when it is written iteratively instead of recursively).
>
> perhaps you should post your program so we can see if it is obviously and
> wastefully recursive?
> RJF
>
>
>
> van Nek wrote:
>
>> Am 5 Apr 2007 um 10:35 hat sen1 at math.msu.edu geschrieben:
>>
>>> Hello,
>>> On some simple procedures, I get a 'bind stack overflow'.
>>
>>
>> Sheldon,
>>
>> I guess, you are using a recursive algorithm. Translating to Lisp and/or
>> compiling helps a lot to increase the number of possible iterations, but at
>> a certain amount you'll get this message again. If your algorithm needs
>> thousands of iterations you better should look for nonrecursive code.
>>
>> Volker
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Maxima mailing list
>> Maxima at math.utexas.edu
>> http://www.math.utexas.edu/mailman/listinfo/maxima
>>
>