MathGroup Archive 2000

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

Search the Archive

Re: Using user-defined functions (newbie question)

  • To: mathgroup at
  • Subject: [mg22373] Re: Using user-defined functions (newbie question)
  • From: "Allan Hayes" <hay at>
  • Date: Sat, 26 Feb 2000 22:05:00 -0500 (EST)
  • References: <897ffi$>
  • Sender: owner-wri-mathgroup at

"Chris Deacon" <cdeacon at> wrote in message
news:897ffi$63u at
> Suppose I define a function, called myfunc[a_,b_,c_]:=
> several_lines_of_code
> How can I call this function in another notebook without retyping
> entire function, so that the command
> value=myfunc[x,y,z] will give me the desired result?
> Do I simply include a Needs command at the top of the worksheet, or
> what?
> Chris Deacon

If you have not closed the kernel or cleared the definition (for example
with Clear[myfunc] )then function will work as defined in any notebook.

If you want to make function available in other sessions and to other
notebooks then a simple way is illustrated below

myfunc[x_] := x^2

Save the definition to a file (you can  use your own file name)

Save["myfunc", myfunc]

Clear the definition ( or quit the kernel and restart)


But we can call the definition from the file




Going beyond this we might make a package

Allan Hayes
Mathematica Training and Consulting
Leicester UK
hay at
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

  • Prev by Date: Re: Help needed: How to add constraints into FullSimplify
  • Next by Date: Re: algebraic manipulation
  • Previous by thread: Using user-defined functions (newbie question)
  • Next by thread: Mathmatica Art