1
$\begingroup$

I am using Manipulate to plot a function that takes a fair amount of time to be plotted. Once it is done I would like to change the y-range where it is plotted. To avoid that the function is evaluated again I am trying to use Dynamic. Following an example in Wolfram Documentation I constructed something like this:

Manipulate[
    Plot[f[a,x],{x,0,xmax},PlotRange->Dynamic[{0,xmax}]],
    {a,amin,amax},{xmax,0.1,5}
]

However, I get an error:

General::prng: Value of option PlotRange -> {0,0.1} is not All, Full, Automatic, a positive machine number, or an appropriate list of range specifications.

Any ideas on how to solve this?

$\endgroup$
0

1 Answer 1

2
$\begingroup$

This version recomputes f[a, x] when the y-range is changed

f[a_, x_] := a Sin[x]
{amin, amax} = {1, 2};
Manipulate[Plot[f[a, x], {x, 0, xmax},
  PlotRange -> {{0, xmax}, {ymin = -ymax, ymax}}],
 {a, amin, amax}, {xmax, Pi, 2 Pi}, {ymax, 2, 6}]

However, in this version the y-range is fixed ...

f[a_, x_] := a Sin[x]
{amin, amax} = {1, 2};
ymax = 2;
Manipulate[plot = Plot[f[a, x], {x, 0, xmax},
   PlotRange -> {{0, xmax}, {ymin = -ymax, ymax}}],
 {a, amin, amax}, {xmax, Pi, 2 Pi}]

but it can be rescaled in a further manipulate without recalculation.

Manipulate[plot /.
  (PlotRange -> {i_, {j_, k_}}) :> (PlotRange -> {i, {-m, m}}),
 {m, 2, 4}]
$\endgroup$
2
  • $\begingroup$ Thanks for your answer Chris. To avoid having two plots I have nested the two Manipulate functions. Seems to be working fine. $\endgroup$
    – Patricio
    Nov 5, 2020 at 13:05
  • $\begingroup$ @Patricio Cool. You should post your solution. I, for one, would be interested to see it. $\endgroup$ Nov 5, 2020 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.