Typing things in:

  • End each line you want to execute with either <Shift>-<Return> (i.e., hold down the Shift key when you hit return) or by using the <Enter> key on the numeric keypad (far right side of the keyboard).  If you enter something and nothing happens, you probably forgot to do this.
  • Use the “tool palettes” to enter most special symbols, such as square roots, integral signs, matrices, summation signs, Greek letters, etc.  These can also be used to enter many common commands, such as integration, differentiation, etc.  The main palettes are:
    • Basic Input – This is the most useful palette.  It contains buttons for the most common mathematical symbols (including integration, summation, and differentiation) and the Greek alphabet.
    • Basic Calculations – This is a good expandable tree listing of a lot of useful commands, including algebra, calculus, trig, graphing, and matrices, sort of a “starter set” of Mathematica commands.
    • Algebraic Manipulation – This has functions that will do things like simplify, factor, cancel, collect like terms, etc.
    • Others – There are others you probably won’t use as often for things like access to some less common symbols, etc.
  • When you enter something from a tool palette that has small "placeholder" boxes to fill in (like ), use the <Tab> key to move from box to box and fill them in.
  • Implicit multiplication is recognized, as long as there is a space between the different elements.  So x y z is fine, but xyz isn’t (Mathematica thinks this is a single variable called “xyz”), or x Sin[y] is good, while xSin[y] isn’t.
  • If you need help on a command, type in the command name, highlight it, and press the <F1> function key.  This opens the help browser to that command.
  • Useful keyboard shortcuts (taken from the Mathematica online help):

  • To exit an exponent/square root/subscript/etc., either press  or the right arrow key.
  • To stop a computation that is in progress (and perhaps taking too long), go to the Kernal->Interrupt Evaluation (shortcut Alt-,) menu item or to the Kernal->Abort Evaluation (shortcut Alt-.) menu item.
  • Triple-click on something with the mouse to highlight that entire object (like a command or a function and its parameters).

Grouping Symbols:

Symbol

Usage

Good example

Evil example

Parenthesis
 ( )

Used for all mathematical grouping, but not for function notation.

f(x+h) – f(x)

Square brackets
 [ ]

Used only for the arguments of a function, never for mathematical grouping. This includes built-in functions as well as those you define yourself

f[x+h] – f[x]
Sin[x]
fVector[x,y,z]


this should be:

Curly brackets
{ }

Used anytime a “list” of things is needed (but not for mathematical grouping). This includes entering vectors and matrices, as well as when entering a list of functions to graph (in 2 dimensions).

The vector <1,2,3> would be entered as {1,2,3}

 

The equals sign(s):

Symbol

Usage

Example

==

Use this when you want to enter an equation (in order to solve, for example).


NOT
 

=

Assign a value to a variable or a function immediately.  I suggest using this to make assignments to variables.*

x=3 means that from the time this is executed until the next assignment to the variable x, x will always evaluate to a 3.

:=

Assign a definition to a function name (or a value to a variable) for when it is next called.  I suggest using this to make definitions to functions most of the time.*

If you execute f[x_]:=x2, then f[3] would evaluate as 9.

 

* - Actually, this isn’t really what the difference is between = and :=.  Technically, it has to do with when the assignments are made (for both functions as well as variables).  = executes the assignment immediately while := executes it the next time the symbol is called (i.e., it is like the difference between compile-time and run-time expansion).  Also, either symbol can really be used with both functions and variables.  However, for most practical purposes, the way I present things here is a safe way to use them and will minimize unexpected consequences.


Using built-in functions:

  • All built-in functions begin with a capital letter; case does matter. 
  • All function arguments must be enclosed in square brackets [ ].

Good:

Sin[x],  Cos[x],  Exp[x],  Log[x]  (warning: Log means natural log in Mathematica)

Evil:

Tan(x),  sin[x],  ln[x], LOG[x]

  • Some built-in
  • Some functions have special shortcuts:
    •   - This is not the standard letter e; you must use the tool palette to enter it
    • 3!  -  factorial
    •   for integration (you have to fill in the boxes)
    • for partial derivatives (i.e., with respect to x here)
    •   for the (single variable) derivative
    •   for the dot product (this is just a standard period between the vectors)
    •   for the cross product; this is not the same symbol used for multiplication – it is on the “Basic Input” tool palette just to the right of the ÷ sign.
  • Some functions must be loaded from special “packages” before they can be used.  If you forget and use the function name first, you will need to use the command “Clear” to make the function work again after loading the package (or, if you don’t mind re-executing everything in your notebook, it is sometimes easier to choose “Kernal -> Quit Kernal” from the menu).  Some commonly need packages include:
    • <<Graphics` - This loads certain special graphics commands, such as PolarPlot
    • <<RealTime3D` - This loads a package that allows you to rotate 3-dimensional graphs just by dragging them with the mouse.  There is a bug that causes this to not work properly in some cases (like trying to display two 3-D graphs on the same axes).
    • <<Default3D` - This unloads the RealTime3D package to deal with the bug mentioned above.

Defining your own functions:

  • The current definition of a function or variable is the last one that was executed, not necessarily the last one on the page.  (This is only a problem if you skip around on the page and re-execute lines.)  If you execute a new definition of a function or variable, it will replace the old one.
  • You must execute the definition of a function before you can make use of it.
  • Functions are defined as follows:

    ·         On the left side of each definition, you must give the function name and list its independent variables, each one with an underscore after it (i.e., x_).  The underscore is very important; it tells Mathematica that anything can be substituted for this variable.

  • ·         Then there must be a := symbol, and then the definition.  If any variables appear on the right that are not in the list of independent variables on the left, they are considered constants.  (So a, b, and c in function g above are constants.)

    • After defining them, functions can be called with numbers and/or variables as arguments:

       (g defined as above)

  • A vector-valued function can be defined in one of two ways:

    1.          (This defines a functions from  into .)

    2.        However, if you want to be able to compose two multi-variable functions easily later, it would be better to define them:


    (Note the extra { }’s in the definition.)  This is a pain if all you want to do is find T[{1,2}] (method 1 would be easier as T[1,2]), but it makes it easy to do the following:
     will be

Common mistakes:

Many of the Mathematica error messages are rather cryptic, so here are some very common errors people make that you should check when things go wrong:

  • Did you remember to hit <Shift>-<Return> (or <Enter> on the numeric keypad) at the end of your command? 
  • No space between variables (implicit multiplication)
  • Wrong type of ( )'s, { }'s, or [ ]'s
  • Used an = sign in an equation (rather than ==)
  • Forgot the _'s in defining a function (this one is easy to forget)
  • Incorrect case in function/variable names (remember that ALL Mathematica functions begin with a capital letter)
  • Remember that natural log is Log in Mathematica
  • Be sure to load any required packages before calling one of the functions in that package.  (This is also an easy one to forget.  It is especially annoying because if you DO forget and call the function first, Mathematica thinks you are defining your own new function and this will "hide" the real function if you subsequently load the package.  You must either quit the kernal and re-execute everything or use the Remove command.)
  • Entering a command that refers to something (variable assignment or function definition) that has not been executed in the current session.  Just because you see it on the screen doesn't mean it has been entered; Mathematica only "knows" things that have been executed (<Shift><Return>) in the current session.
  • Setting a variable assignment (or function definition) at one place and using it again for a different purpose later without remembering the original assignment.  (You can use the Clear command to make Mathematica "forget" the first definition/assignment.) 
  • If a calculation is taking a ridiculous amount of time (or it looks like it will never finish), try doing it numerically rather than symbolically.  You can usually do this easily by adding a decimal point to any number involved in the function/variable.