Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Can model parameters be global?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg79920] Re: Can model parameters be global?
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Thu, 9 Aug 2007 05:10:05 -0400 (EDT)
  • References: <f9c1av$6it$1@smc.vnet.net>

Neil Stewart 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.
> 
> 

If I were performing physical calculations, I would use:

Needs["Units`"]

Needs["PhysicalConstants`"]

These would provide the necessary physical constants.

Beyond that, I think global variables can be very useful, but I would 
always give them long names such as SpeedOfLightInWater (not c) to 
minimise the possibility of confusion. The PhysicalConstants package 
itself uses this style.

The issue with regard to Manipulate is a little different. The 
Manipulate object looked the same for me with either approach - why do 
you say it was a "right mess"?

However, the only point in using LocalizeVariables -> False would be to 
keep the final control settings from Manipulate - in which case you 
presumably don't want to clear these results immediately!

In general, I would decide to use global variables (or not) on other 
considerations, and make Manipulate work with whatever suits you best.

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Re: How show Locator point and its image under a function?
  • Next by Date: Re: Beta function, Integral
  • Previous by thread: Re: Can model parameters be global?
  • Next by thread: Re: Can model parameters be global?