1

I have the following functions:

P[t_] := P[t] = P[t-1] +a*ED[t-1];
ED[t_] := ED[t] = DF[t] + DC[t];
DF[t_] := DF[t] = b (F - P[t]);
DC[t_] := DC[t] = c (P[t] - F);

And the following parameters:

a=1;
c=0.2;
b = 0.75;
F=100;

In Mathematica I use the function "ListLinePlot" in order to plot P[t] and F:

ListLinePlot[{Table[P[t], {t, 0, 25}], Table[F, {t, 0, 25}]}, PlotStyle → {Black, Red},Frame → True, FrameLabel → {"time", "price"}, AspectRatio → 0.4, PlotRange → All]

How can I do this in wxMaxima? Is there a similar function or an alternative to ListLinePlot?

This is my attempt in wxMaxima:

P[t] := P[t-1] + a * ED[t-1];
ED[t] := DF[t] + DC[t];
DF[t] := b*[F-P[t]];
DC[t] := c*[P[t]-F];

a=1;
c=0.2;
b=0.75;
F=100;

And then I tried:

draw2d(points(P[t], [t,0,25]))

The plotted function should look like this: enter image description here

Lagrange
  • 61
  • 6
  • Unfortunately I can't go into details at the moment, but some ideas that you can consider. Maybe some of this you know already, but anyway. Assignment in Maxima is `:` and function definition is `:=`. Ordinary (non-memoizing) functions are defined with parentheses e.g. `f(x) := ...` while so-called "array functions" (memoizing) are defined with square brackets, e.g. `g[x] := ...`. You can call `makelist` to make a list of values. You can plot a list via `plot2d([discrete, ...])` or `draw2d(points(...))`. Btw it looks like you say `F = 100` but then `F` is a function?? Maybe you can clarify. – Robert Dodier Dec 28 '20 at 18:07
  • Thank you for your reply. Your remarks with regards to the differences between the parentheses were very valuable for me. Unfortunately, I still do not understand how to plot the functions. F is not a function. It is a price (fundamental price); the price should be plotted on the y-axis and the time on the x-axis. I have tried: draw2d(points(P[t], [t, 0,25], F, [t,0,25]) but it did not work. – Lagrange Dec 28 '20 at 20:48
  • About F, all I see in your example is `F = 100` and later `Table[F, {t, 0, 25}]` which, I gather, is creating a list of items for F(0), F(1), F(2), ..., F(25). So what I'm wondering is how the value of F(t) is known. I think it would help a lot at this point if you update your question to show the Maxima code you have written so far. – Robert Dodier Dec 28 '20 at 21:16

1 Answers1

1

OK, I've adapted the code you showed above. This works for me. I'm working with Maxima 5.44 on macOS.

P[t] := P[t-1] + a * ED[t-1];
ED[t] := DF[t] + DC[t];
DF[t] := b*(F-P[t]);
DC[t] := c*(P[t]-F);

a:1;
c:0.2;
b:0.75;
F:100;
P[0]: F + 1;

Pt_list: makelist (P[t], t, 0, 25);

load (draw);
set_draw_defaults (terminal = qt);
draw2d (points_joined = true, points(Pt_list));

Notes. (1) There needs to be a base case for the recursion on P. I put P[0]: F + 1. (2) Assignments are : instead of =. Note that x = y is a symbolic equation instead of an assignment. (3) Square brackets [ ] are only for subscripts and lists. Use parentheses ( ) for grouping expressions. (4) Syntax for draw2d is a little different, I fixed it up. (I put a default for terminal since the built-in value is incorrect for Maxima on macOS; if you are working on Linux or Windows, you can omit that.)

EDIT: Try this to draw a horizontal line as well.

draw2d (points_joined = true, points(Pt_list),
        color = red, points([[0, F], [25, F]]), 
        yrange = [F - 1, P[0] + 1]);
Robert Dodier
  • 16,905
  • 2
  • 31
  • 48
  • Thank you so much for your great explanation! This will help me to better understand how Maxima works. Unfortunately, I still have a problem: how can I draw the red line at y=100? I tried 'yline=100' within the 'draw2d' function but it did not work. – Lagrange Dec 29 '20 at 09:51
  • By the way: I get the following message: "qt.qpa.fonts: Populating font family aliases took 304 ms. Replace uses of missing font family "Sans" with one that exists to avoid this cost. Error: plot window (gnuplot_qt) not responding - will restart" Is this "normal" or should I do something about it? – Lagrange Dec 29 '20 at 10:05
  • I've updated the answer to show how to draw a horizontal line. About the font family message, I am guessing you are working on macOS. The problem is that Gnuplot, which Maxima calls to make plots, says the default font is "Sans" which doesn't exist on macOS, and there is no simple way to detect this situation in Maxima. I think the font message is harmless, but "plot window not responding" sounds more serious. Do you actually see a plot, or not? – Robert Dodier Dec 29 '20 at 16:40
  • Yes, I can see the plot and everything looks fine. Thank you again for your help. It has helped me a lot to better understand wxMaxima. – Lagrange Dec 29 '20 at 18:37