MathGroup Archive 2000

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

Search the Archive

Re: Using user-defined functions (newbie question)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg22373] Re: Using user-defined functions (newbie question)
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Sat, 26 Feb 2000 22:05:00 -0500 (EST)
  • References: <897ffi$63u@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

"Chris Deacon" <cdeacon at .physics.mun.ca> wrote in message
news:897ffi$63u at smc.vnet.net...
> 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
>


Chris,
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)

Clear[myfunc]

But we can call the definition from the file

Get["myfunc"]

myfunc[2]

    4

Going beyond this we might make a package


Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
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