MathGroup Archive 2012

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

Search the Archive

Re: Begginer's question: Saving a function for later use

  • To: mathgroup at
  • Subject: [mg128046] Re: Begginer's question: Saving a function for later use
  • From: "djmpark" <djmpark at>
  • Date: Tue, 11 Sep 2012 02:33:29 -0400 (EDT)
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • References: <19207797.49366.1347264435806.JavaMail.root@m06>


Any definitions you make within a notebook are only active in the current
session. If you quit Mathematica and then reopen your notebook you will have
to reevaluate your definitions.

There are several common and simple ways to handle this.

1) Make your definitions Initialization cells. You can do this on the
context menu for a cell and selecting Initialization Cell. Then when you
reopen the notebook and try to evaluate any cell Mathematica will ask if you
want to evaluate all the Initialization cells first.

2) It is useful to learn how to use Sections, and also Text cells for
commentary and description. Then you could make an Initialization Section
near the top of your notebook that would contain all the definitions that
are initialized. If a definition is a more extended routine you could
develop it in a development Section and then when it works move it to the
Initialization Section.

3) Again if you have material for a certain calculation, say,  in a Section
by itself you could just evaluate the entire Section when you reopen the
notebook to get started again. You wouldn't have to make any of the
definitions there Initializations cells.

So Sectional organization and Initialization cells are convenient ways to
organize your work.

Later, when you develop a number of really useful routines, you could think
of putting them into a Mathematica package, which isn't terribly difficult,
and then any notebook that needed to use the routines in the package would
just load the package near the top of the notebook, and this itself could be
an Initialization cell.

David Park
djmpark at 

From: pedro.roberto at [mailto:pedro.roberto at] 

I'm just getting started on Mathematica and trying to define a function for
later use. The function is just:


While I don't close mathematica, I can use the function on my notebooks but
when I close it, the function disappers, I tried to save a .m file with it
but It didn't work. What do I do?

Thanks for time,

  • Prev by Date: Re: A new FrontEnd
  • Next by Date: compile fct. using Goto and If (vrs. 8)
  • Previous by thread: Re: Begginer's question: Saving a function for later use
  • Next by thread: compile fct. using Goto and If (vrs. 8)