1

I have the following Maxima code:

A[t] :=  
    if t=0 then A0
    else (a+b)*A[t-1]+B[t-1]+c
;
B[t] :=
    if t=0 then B0
    else (a-b)*B[t-1]+c
;
a:0.1;
b:0.1;
c:1;
A0:100;
B0:0;
wxplot2d(A[t], [t, 0, 100]);

The only remotely weird thing I can think of is that recurion equation A depends on recurion equation B. I would think everything else is extremely basic.

But when I run it, I always get the following error repeated multiple times and no plot.

Maxima encountered a Lisp error:
 Control stack exhausted (no more space for function call frames).
This is probably due to heavily nested or infinitely recursive function
calls, or a tail call that SBCL cannot or has not optimized away.

Even when I plot from time steps 0 to 1 with wxplot2d(A[t], [t, 0, 1]);, which by my count would only be two recursions and one external function reference, I still get the same error. Is there no way to have Maxima plot these equations?

  • `wxplot2d` is going to try to evaluate the function for many points in the range of `t`, including noninteger values, but it looks like your functions are defined only for integer values. Try constructing a list of values of A and B just for integer values, and then plot that list. Something like `myvalues: makelist(A[t], t, 0, 100);` and then plot `myvalues`. I can't try it right now, I'll try to look at it later. – Robert Dodier Dec 10 '21 at 18:34

1 Answers1

0

I find that the following seems to work.

myvalues: makelist ([t, A[t]], t, 0, 100);
wxplot2d ([discrete, myvalues]);

Just to be clear, A[t] := ..., with square brackets, defines what is called an array function Maxima, which is a memoizing function (i.e. remembers previously calculated values). An ordinary, non-memoizing function is defined as A(t) := ..., with parentheses.

Given that A and B are defined only for nonnegative integers, it makes sense that they should be memoizing functions, so there's no need to change it.

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48