Indiana University
University Information Technology Services
  
What are archived documents?

In Mathematica, if I forget to load a package before I first use one of its functions, how can I recover?

If you forget to load a package in Mathematica before you first use one of its functions, use the following command to recover:

Remove["function"]

Replace function with the name of the function. You can then load the package successfully.

Suppose that in a Mathematica session you try to find the mean of a list of numbers without first loading the appropriate package, for example:

Mean[{3,4,5}] Out[1] = Mean[{3,4,5}]

There isn't an error message, but Mathematica didn't do what you wanted; rather, it returned your input unchanged. When you realize your error and load the descriptive statistics package, the Mean function will still be unavailable, since your earlier use of the term has pre-empted it. When you load the package, you receive the following warning:

"<<Statistics`DescriptiveStatistics`

Mean::shdw: Warning: Symbol Mean appears in multiple contexts

{Statistics`DescriptiveStatistics`, Global`}; definitions in context Statistics`DescriptiveStatistics` may shadow or be shadowed by other definitions."

This means that the earlier use of Mean established its existence in the Global context, which takes precedence over the one you want. However, you can use the following command to make the statistical function available:

Remove["Mean"]

The following statistical function will result:

Mean[{3,4,5}] Out[5] = 4

In the current version of Mathematica, it does not matter whether you load first and then Remove, but it is is more intuitive to Remove first and then load the correct package.

For more information about statistical and mathematical software, email the UITS Stat/Math Center, visit the center's web page, or phone 812-855-4724 (IUB) or 317-278-4740 (IUPUI). The center is located in Bloomington at 410 N. Park Avenue, and is open for consultation by appointment Monday-Friday 9am-5pm.

Also see:

This is document afto in domain all.
Last modified on November 17, 2008.
Please tell us, did you find the answer to your question?