       RE: Programing in MATHEMATICA

• To: mathgroup at smc.vnet.net
• Subject: [mg39555] RE: [mg39534] Programing in MATHEMATICA
• From: "David Park" <djmp at earthlink.net>
• Date: Sun, 23 Feb 2003 04:59:54 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

KY,

To evaluate an entire notebook, use menu\Kernel\Evaluation\Evaluate
Notebook.

If you are a relatively new user of Mathematica, then I strongly recommend
spending some time to learn its basics. Read Steven Wolfram's essay
"Suggestions about Learning Mathematica" at the beginning of The Mathematica
Book. Then work through all the relevant sections in Part I, actually typing
in the commands. This will give you basic familiarity with Mathematica's
structure, syntax and commands. In the long run it will save you a lot of
time.

In my mind, there is not much difference between just using Mathematica and
"programming in Mathematica". If you simply write a definition such as

f[a_,b_,c_][x_]:= a Sin[b x + c]

then Mathematica remembers the definition and uses it whenever you type an
expression that matches the definition. Thus it is like a subroutine. For
example...

f[10, w, phi][x]
10 Sin[phi + w x]

or the derivative...

f[A, 20Pi, Pi]'[t]
-20*A*Pi*Cos[20*Pi*t]

Despite the large number of commands in Mathematica and the packages, you
will almost always find that you have to write some of your own definitions
and routines. That is because mathematics and its applications in science
and engineering are so vast that Mathematica could not possibly provide a
single command for every useful operation. There would be millions of them
and then people would complain about not being able to find the one you
want.

To develop a specific application with Mathematica I recommend the
following. First learn how to use notebooks, how to enter Text cells for
discussion and comments, how to use grouping in Sections, Subsections etc.,
and how to open and close sections. (You would be surprised how many really
intelligent and sophisticated people don't know how to open and close
groups! Just double-click the bracket on the right.) Always stay with the
default Automatic Grouping. I have never seen a good notebook with Manual
Grouping.

Then put an Initialization Section at the top of the notebook where you load
any packages used and have any general initialization statements. Next put a
Routines Section. As you develop general routines (i.e., Mathematica
definitions) that you use in your application, put them in the Routines
section. You might say that that section contains the programming code.
Later, if you accumulate a set of really useful routines you can then easily
convert them into a package.

When writing definitions for functions and routines that have some
complication to them, I find it helpful to write usage messages. Many people
find this an unnecessary chore that they can skip. However, it helps clarify
in one's own mind exactly what the routine is supposed to do, it provides
useful information for other users (and for yourself if you come back to it
much later) and if you start the usage message with the command and its
arguments, it provides command completion when you use Ctrl-K. Lastly, you
will need the usage messages anyway if you ever move the routines to a
package.

It is also worthwhile learning how to use Initialization cells. If you make
your Initialization and Routines cells Initialization cells, then
Mathematica will automatically evaluate them when you first try to evaluate
any cell in the notebook. When you first save such a notebook you will get a
dialog box. Choose Don't Create Auto Save Package.

Then you can have additional notebook Sections for specific calculations
that use the routines. If you send the notebook to somebody else, everything
will automatically initialize, and they can get right to the calculations.

So there is no specific section of The Mathematica Book about programming
because essentially the entire book is about programming. If you want to
write packages, then a good but somewhat advanced book is "Programming in
Mathematica: Third Edition" by Roman Maeder. Also look up Packages in the
MathGroup Archives.

David Park

From: KY Jayaram [mailto:kyjayaram42 at yahoo.com]
To: mathgroup at smc.vnet.net

From: K Y JAYARAM
To: mathgroup at smc.vnet.net
NATIONAL AEROSPACE LAB,
BANGALORE,  INDIA

I am a  user of MATHEMATICA , can somebody help me
with information regarding "Programing in
MATHEMATICA".Does MATHEMATICA have programing
structures like asubroutine of FORTRAN or functions of
C language? I looked the entire MATHEMATICA BOOK
version 4 and found no mention about these things.
Also Iwould like to know how to execute a Wole
notebook when it is opened.