Introduction to Mathematica at UMBC


Contents

  1. Getting To Mathematica at UMBC
  2. General Use of Mathematica
  3. Linear Algebra Commands
  4. Number Theory Commands

[Prev] [Mathematica Intro] [Next]

Mathematica is a commercial symbolic algebra system which allows computations in many fields of mathematics and engineering. Packages can be used to extend the Mathematica language in areas where the basic language is weak.

Getting To Mathematica at UMBC

At UMBC you may either purchase a personal copy of MATHEMATICA, using the site license, or use the MATHEMATICA installation on the UMBC machines.

UMBC has a site license for MATHEMATICA which allows students to install it on the own PCs or Macs. The bookstore will sell you copies for about $10. Details of the site license can be read by logging into my.umbc.edu and selecting the Business Services tab.

(??Need to check??) Mathematica is available at UMBC in the microcomputer labs in the Computer Science and Engineering building. It is also available on UMBC servers which are accessible across the internet or by dial-in access. Access to either set of machines is available to any UMBC student using the account name and password they use for e-mail. Account names and passwords are available from the help desk in the CS & Eng building.

2. General Use of Mathematica

The Basics

At the Mathematica command prompt (which usually looks something like In[1]:=) type the command to be run, and then press the Return key to have Mathematica evaluate the command. As a simple example, if you want to add two integers type:

3 + 12

Intermediate values can be saved by giving them a name and assigning them a value with the "=" operator. If the following two commands are run the second output will be 1:

thesum = 3 + 12
thesum - 14

Mathematica uses square brackets for functions and reserves the usual round brackets for grouping operations. Thus, to take the sin of 3, add it to 5, and divide the result by 2 we would write (Sin[3] + 5)/2.

Mathematica is very careful about exact values. Exact values are things like symbols and integers. Thus Sin[3] is an exact value and when you evaluate Sin[3] you get Sin[3] back as an answer. Contrast this with the fact that 3.0 is an approximate value and thus Sin[3.0] evaluates to the approximate value 0.14122. The N[] operator will force a numerical evaluation.

In[1]:= Sin[3]
Out[1]= Sin[3]

In[2]:= Sin[3.0]
Out[2]= 0.14112

In[13]:= N[Sin[3]]
Out[13]= 0.14112

When you are done with Mathematica, type the command Quit (remembering the capitalization) and press the return key.

Help on Mathematica Commands

There are several ways to find help in Mathematica. You can search by the specific Mathematica command (if you know it). The basic help request is
?cmd.
This only works if cmd is a correctly spelled (and capitalized) Mathematica command. A slight improvement can be gained with the use of the wildcard * (any string of characters).

In[9]:= ?Plus
x + y + z represents a sum of terms.
In[12]:= ?Add*
AddOnHelpPath AddTo

More detailed information (although generally not more helpful) can be gotten with the double question mark operator.

In[17]:= ??Plus
x + y + z represents a sum of terms.

Attributes[Plus] = {Flat, Listable, NumericFunction, OneIdentity, Orderless, 
   Protected}
 
Default[Plus] := 0

A more common situation is when you know your topic but don't know the name of the appropriate command. Currently, the best solution for this is to refer to the Mathematica Book, either in hard copy or the web-based version freely available at documents.wolfram.com.

Editing Command Lines

When working with Mathematica on the Windows/Mac interface you can edit a command using the usual mouse, click and type method. If you are working across a network connection Mathematica is clumsier to work with than say, Maple, as there is no way to edit a line short of backspacing to the error and retyping the end of the command. Arrow keys are not recognized and there isn't a simply accessible command history.

Mathematica does have a fairly complete way of referring to previous expressions. Each line is numbered. A command may be referred to by it's number or by how far back it was. Thus, command -1 is the previous command. The various mechanisms are:

Note that re-executing a command with In[n] may not give the same result as simply recalling its original output with Out[n].

In[1]:= x=2
Out[1]= 2

In[2]:= x+y
Out[2]= 2 + y

In[3]:= x=3
Out[3]= 3

In[4]:= x+y
Out[4]= 3 + y

In[5]:= In[2]
Out[5]= 3 + y

In[6]:= Out[2]
Out[6]= 2 + y

In[7]:= InString[2]
Out[7]= x+y

[Prev] [Mathematica Intro] [Next]
Robert Campbell
28 December, 2000