Question: How to code sliders to make it easy to add new ones?

My goal is to find a way to code sliders that set parameters for a plot so that it is not necessary to re-code all of the existing sliders when a new one controlling the same plot is added.

The closest I've come is the following.   Say I've defined a couple of functions

f:= (A,x) ->  sin(A*x);

g := (B,x) -> cos(B*x);

and

plot0 := plot([f(A,x),g(B,x)],x=a..b,color[blue,red]);  

And two sliders with code for action

A := Do(%Slider0)

Do(%Plot0=plot0(A,B));

(and similarly for slider 1 controlling B) when I adjust the sliders the plot updates dynamically as I want.

The trouble is, when I add another slider I must update the code in all of the previous ones to include the new parameter arguments.   I need to be able to create a worksheet to which I can add sliders WITHOUT having to update all the previous ones ...  in other words, I need to find a way to make this work without it being necessary for the slider parameters to be arguments of plot0.  

I've tried a variety of things... defining the functions with and without the parameters as arguments, permutations with subs, and so forth, but the bottom line is I can't find a way to pass the slider value to the plot command.  

Interestingly, if I, say define h := x-> C*x^2 and make the slider code C := Do(%Slider2); Do(%Plot0=plot(h(x),x=-5..5));, say it works fine.   But if I define ploth :=  plot(h(x),x=-5..5); and change the slider code to Do(%Plot0=ploth);, it doesn't work.   I could then easily add functions to ploth and corresponding sliders and I would be good to go.  I expect there's something simple I'm missing that would make this work ... help?

 

Thanks, David

Please Wait...