Re: Can model parameters be global?

*To*: mathgroup at smc.vnet.net*Subject*: [mg79918] Re: Can model parameters be global?*From*: ben <benjamin.friedrich at gmail.com>*Date*: Thu, 9 Aug 2007 05:09:03 -0400 (EDT)*References*: <f9c1av$6it$1@smc.vnet.net>

Dear Neil a convenient work-around is the use of Replace, ReplaceAll; a typical piece of my code looks like this: (* a1 does rarely change in the notebook *) a1=0; (* a2 can take different values in different scenarios, can be used as fit parameter, etc. *) case1:={a2->0} case2:={a2->1} (* a3 is varied continously, eg. in plots *) f[a3_]:=a1+a2+a3; f[1] f[1]/.case1 Bye Ben On 8 Aug., 11:10, Neil Stewart <neil.stew... at warwick.ac.uk> wrote: > When implementing a mathematical model in physics or psychology, for > example, how do other people deal with model parameters in Mathematica? > Would you represent the speed of light as a global variable or a local > variable. For example, would you use > > Energy[m_]:=m*c^2 (* c is a global variable *) > > or > > Energy[m_,c_]:=m*c^2 (* c is a local variable *) > > ? > > The first seems neater. But problems arise in psychology, my domain, where > the values of model parameters are unknown and are left as free parameters, > adjusted to best-fit the data. > > Both local and global methods work well with optimisation. For example, > > NMinimize[Energy[1],{c}] > {0., {c -> 0.}} > > and > > NMinimize[Energy[1,c],{c}] > {0., {c -> 0.}} > > But the global variable solution does not work well with Manipulate. > For example, > > Manipulate[Dynamic[Energy[1]], {c, 0, 1}, LocalizeVariables -> False] > > works, but looks a right mess and also results in c taking a value that > needs a Clear[c] before using other functions like NMinimize. On the other > hand the local variable version > > Manipulate[Energy[1, c], {c, 0, 1}] > > is nice and simple. But the local variable solution results in having to > pass all of the model parameters to the function. This is fine in this > trivial example, but becomes unwieldy when there are ten model parameters > and the model is defined using a set of functions. (A c-like struct could > help, but there does not seem to be a neat way to do this in Mathematica.) > > So what do other people do? I'd be really interested to hear.