Localized Variables and Switches

Local Variables

In the above, the values of a and  xvalue are used repeatly—however, if we are only interested in the resulting minimum, their final values have little meaning or importance.  Suppose, we use the value of a or xvalue without clearing—what will the value be?





As this could cause problems if a is used in a function call, say Sin[2 π a], it is a good idea to localize variables.









Switches: If, Which









The above program is ok, but not very useful because it only works for  the current value of a.  It would be more useful to have something that worked for any value of a and could use it over again—that is, turn it into a tool.  This involves patterns and function definitions.

Spikey Created with Wolfram Mathematica 6