1
$\begingroup$

This is a sample snippet from Mathematica documentation for plotting Bessel for various n:

Plot[Evaluate[Table[BesselJ[n, x], {n, 4}]], {x, 0, 10}, 
 Filling -> Axis]

enter image description here

How can you use Manipulate[] to animate this over both x and n (so if I wanted a slider for x and n). I've tried this:

Manipulate[
 Plot[Evaluate[Table[BesselJ[n, x], {n, 4}]], {x, 0, xmax}, 
  Filling -> Axis],
 {xmax, 0, 10 , Appearance -> "Open"}
 ]

But get this error:

enter image description here

$\endgroup$

1 Answer 1

1
$\begingroup$

Replace 0 in {xmax, 0, 10 , Appearance -> "Open"} with a small number (say, 10.^-5) to avoid the error:

Manipulate[Plot[BesselJ[n, x], {x, 0, xmax}, Filling -> Axis, 
  PlotRange -> {{0, 10}, {-.7, .7}}], 
{xmax, 10.^-5, 10, Appearance -> "Open"}, 
{n, 1, 4, 1}]

enter image description here

Use TogglerBar as control to select subsets of Range[5] to as the parameter n:

Manipulate[Plot[Evaluate[BesselJ[#, x] & /@ n], {x, 0, xmax}, 
  Filling -> Axis, 
  PlotRange -> {{0, 10}, {-.7, .7}}], 
{{xmax, 6}, 10.^-5, 10, Appearance -> "Open"},
{{n, {1, 3}}, Range[5], TogglerBar}]

enter image description here

$\endgroup$
1
  • $\begingroup$ when the function is of two varibles like this:Manipulate[ Plot[Evaluate[prob[y, t, #] & /@ n], {y, 0, 2}, Filling -> Axis, PlotRange -> {{0, 2}, {0, 3}}], {{t, 10.^-5}, 0, TIMELAPSE, Appearance -> "Open"}, {{n, {1}}, Range[10], TogglerBar} ] it's not working and adding new filled plots, how do you do it with two vars? $\endgroup$
    – SOUser
    Commented Mar 6, 2021 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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