The issue
Assume the explicit solution to a differential equation to be:
(%i1) x(t):=((x[0]*%e^(k*t))/(x[0]*%e^(k*t)-x[0]+1))
Obviously the parameter k affects the slope of the solutions, as can be seen by graphing them together for different values of k (in this example, varying from k=0.25 to k=1.75 with step 0.25).
Trying to plot the graphs this way
(%i6) plot2d(
makelist(subst([k=d*0.25,x[0]=0.1],x(t)), d,1,7),
[t,0,15],
cons(legend, makelist("k=d*0.25", d,1,7)),
[gnuplot_preamble,"set key right bottom"]
)$
however yields a plot with "static" labels for each solution:
Next we returned to a solution offered here on stackoverflow (maxima-plotting-in-a-loop) and adapted it to this case:
(%i7) makelist(subst([k=d*0.25,x[0]=0.1],x(t)), d,1,7);
plot2d(%, [t,0,15],
[gnuplot_preamble,"set key nobox spacing 1.1 bottom right"]
)$
This is an improvement over the first attempt, but this code prints the entire function names x(t)=(x_0*e^(k*t))/(x_0*e^(k*t)-x_0+1)
with k=d×0.25,d=1,…,7
as legend labels and thus it is not very reader-friendly.
What we actually want to have in the legend are just the k-values from this list:
(%i8) kV: makelist(k=d*0.25, d,1,7);
(%o8) [k=0.25,k=0.5,k=0.75,k=1.0,k=1.25,k=1.5,k=1.75]
So we tried this to get the following error message:
(%i11) plot2d(
makelist(subst([k=d*0.25,x[0]=0.1],x(t)), d,1,7),
[t,0,15],
cons(legend, makelist(kV)),
[gnuplot_preamble,"set key right bottom"]
)$
Value of option legend. should be a string or false, not "
[k = 0.25,k = 0.5,k = 0.75,k = 1.0,k = 1.25,k = 1.5,k = 1.75]
".
-- an error. To debug this try: debugmode(true);
Does anyone know how to get these k values into the legend?
Any help/suggestions appreciated.
Cheers, Tilda
The issue solved
Robert's suggestion helped. So
plot2d(
makelist(
subst([k=d*0.25,x[0]=0.1],x(t)), d,1,7),
[t,0,15],
cons(legend, map(string, kV)),
[gnuplot_preamble,"set key right bottom"]
)$
Thanks to Raymond's answer and his clarifications on the intricacies of Maxima's printf()
, we now have the icing on the cake:
plot2d(
makelist(subst([k=d*0.25,x[0]=0.1],x(t)), d,1,7),
[t,0,15],
cons(legend, makelist(printf(false,"k = ~,2f", 0.25*d), d,1,7)),
[gnuplot_preamble, "set key nobox spacing 1.1 right bottom"]
)$
A workaround to typesetting titles in a typographically correct way is to use captions, as can be seen from a screenshot of a TeXmacs session. This is not really the jewel to the crown, but pretty close.