# Question:Plot is drawn only after second worksheet execution

## Question:Plot is drawn only after second worksheet execution

Maple

I have a program (its content is not essential, but I inserted it. The values in outer loops were changed to have only one set of initial data).

printlevel := 5;

for a from .5 by .5 to .5 do

for m from -.999 by .4995 to -.999 do

for n from -5 by 5 to -5 do

ODE := diff(diff(x(t), t), t)+.2*(diff(x(t), t))-x(t) = a*sin(t); k := 0;

ics := x(k) = m, (D(x))(k) = n;

for i to 30 do

X[i] := dsolve({ODE, ics[i]});

u[i] := rhs(X[i]);

v[i] := diff(rhs(X[i]), t);

S1[i] := RootFinding:-NextZero(unapply(rhs(X[i])-1, t), k[i]+0.1e-3);

S2[i] := RootFinding:-NextZero(unapply(rhs(X[i])+1, t), k[i]+0.1e-3);

k[i+1] := min(select(type, [S1[i], S2[i]], numeric));

p[i] := evalf(subs(t = k[i+1], u[i]));

q[i] := evalf(subs(t = k[i+1], v[i]));

ics[i+1] := x(k[i+1]) = p[i], (D(x))(k[i+1]) = -q[i];

plot([u[i](t), v[i](t), t = k[i] .. k[i+1]]);

plo[i] := plot([u[i](t), v[i](t), t = k[i] .. k[i+1]])

end do;

print(NOW*WELCOME);

with(plots); display(seq([plo[i]], i = 1 .. 30))

end do

end do

end do

It works fine (thanks mapleprimes forums!) with one major exception. Before execution I restart Maple server (to have memory cleaned), and then the last operation (with(plots):display) does not return a plot and shows

display([PLOT(`...`)], [PLOT(`...`)], [PLOT(`...`)], [PLOT(`...`)], [PLOT(`...`)], [PLOT(`...`)], [PLOT(`...`)], [PLOT(`...`)], [PLOT(`...`)], [PLOT(`...`)])

instead. When I "Execute the entire worksheet"  (without cleaning the memory) again, the correct set-of-plots-on-one-picture is drawn.

But I won't be able to re-execute the program when outer loops are running.

So the questions are.

1. Why doesn't Maple draw a picture in my program from the first attempt?

2. How can the program be improved to get the picture from the first attempt?

Thanks a lot! ﻿