TransWikia.com

Mathematica Manipulate[] for plotting a function of several variables

Mathematica Asked on May 18, 2021

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

One Answer

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

Correct answer by kglr on May 18, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP