# Manipulation of a plot computed in several steps

the following test works for fixed parameter si:

 test = Block[{si = 2},
k = si s^2 + 107 s/5  + 10  ((1 + s)^(-2) - 1) - 1/10;
cr = Chop[N[Solve[k == 0, s], 12]];
Wsa = Apart[(1 + s)^2/(si Product[s - (s /. cr[[i]]),
{i,4}])];
Wp[y_] := D[InverseLaplaceTransform[Wsa, s, x], x] /.x->
y];
Plot[Evaluate[Wp[x]], {x, 0, 16}]


Turning it to Manipulate results in infinite evaluation on 11.3, and messages General::ivar: 0.0003268571428571428 is not a valid variable. Help?

k = si s^2 + 107 s/5  + 10  ((1 + s)^(-2) - 1) - 1/10;
Manipulate[cr = Chop[N[Solve[k == 0, s], 12]];
Wsa = Apart[(1 + s)^2/(si Product[s - (s /. cr[[i]]), {i, 1, 4}])];
Wp[y_] := D[InverseLaplaceTransform[Wsa, s, x], x] /. x -> y;
Plot[Evaluate[Wp[x]] /. {si -> s2}, {x, 0, 16}], {{s2, 1, "s2"}, 1,
2, Appearance -> "Labeled"}]


Here's one approach that may be useful. For clarity, let's obtain an expression for $$W_p$$ by evaluating the following:

ClearAll["Global*"]
wsa = (1 + s)^2/(si  q);
q = (s - cr1) (s - cr2) (s - cr3) (s - cr4);
wp = D[InverseLaplaceTransform[wsa, s, x], x]


The values for $$C_{r1} ... C_{r4}$$ are obtained here:

k = si s^2 + 107 s/5 + 10 ((1 + s)^(-2) - 1) - 1/10;
cr = {cr1, cr2, cr3, cr4} = s /. Solve[k == 0, s];


The list cr just makes it easy to insert intermediate steps like cr /. si->1.5. Now we can create a plot and adjust the plot range to cover a range of si values

Plot[Evaluate[Chop[wp /. si -> Range[1, 2, 1/3]]],
{x, 0, 16},
PlotRange -> {{0, 16}, {0.0225, .0275}}]


The manipualate is slow, taking several seconds to regenerate the plot, so we use later steps for the slider variable, $$\lambda$$

Manipulate[
Plot[Chop[wp /. si -> λ], {x, 0, 16},
Frame -> True, GridLines -> Automatic,
PlotRange -> {{0, 16}, {0.0225, .0275}}],
{{λ, 1.5}, 1, 2, 0.1, Appearance -> "Labeled"}]


The manipulate works, but slowly. The gridlines make is easier to see the changes.

• Thanks! I guess the first plot was like a warmup; or, the fact of computing those values helps somehow to spped the manipulate ? – florin Jun 16 '19 at 13:36
• @florin The first plot shows the scale required for me to see the changes effected by Manipulate. At first I used a 0-0.1 scale and thought the function was independent of $s_i$, or that I had made a mistake. The first plot shows what kind of changes to expect the slider to produce, like a proof of concept. It also shows that complex values should (probably) not be the issue, if something does go wrong in the Manipulate version. – LouisB Jun 16 '19 at 22:15