# List of parameters as argument for Manipulate

Let's say, that we have a list of parameters, that we want to use in manipulate, like so:

parameters={{a,0,5},{b,-1,5}};

Of corse you could manually copy and paste that into Manipulate[], but in the problem I'm actually solving, you can't do that.

Below is a very simple example and 2 versions of the code, that don't work:

VERSION 1

plot1=ListPlot@Table[{x,2x+3}+RandomReal[.4,2],{x,-5,5}];
parameters={{a,0,5},{b,-1,5}};

Manipulate@@Join[
{Show[plot1,Plot[a x + b, {x,-5,5}]]},
parameters
]


VERSION 2

plot1=ListPlot@Table[{x,2x+3}+RandomReal[.4,2],{x,-5,5}];
parameters={{a,0,5},{b,-1,5}};

Manipulate[
Show[plot1,Plot[a x + b, {x,-5,5}]],
Splice@parameters
]


And I tied a few more things, but none of them work. How to do it?

• Rather than eyeball a fit, you should use one of the fitting functions, e.g., Fit, LinearModelFit, or NonlinearModelFit. Mar 18 at 18:10
• This was just an example. For fiting I mostly use NonlinearModelFit. But also for fiting NonlinearModelFit can be very unstble (finding the wrong local RMS minimums). In some cases, like even if you set the initial values quite close, the fit can be completely wrong. In that case doing it manually is probably the best you can (easyly) do. Mar 18 at 18:28
• Okay, probably another easy way would be to Table the NonlinearModelFit for many different initial values of parameters in some ranges, and chose the best one, but it might still be not that stable, and with a lot of parameters, you could only take a few values for each parameter Mar 18 at 18:52
• If you are having a problem with NonlinearModelFit you should post a question showing what you have tried and others might be able to suggest how to overcome the problem. Mar 18 at 19:03
• I'll ask about it the next time Mar 18 at 19:49

Manipulate has a HoldAll attribute, so you have to manually Evaluate the list with parameters. Furthermore, use Sequence to expand the list into a sequence of arguments.
Manipulate[Show[plot1, Plot[a x + b, {x, -5, 5}]],