LESSON 2
 MATHEMATICA AS 
 CALCULATOR

Author's notice

This tutorial was written by 

Fred Goodman
Department of Mathematics
University of Iowa
Iowa City, IA 52242
goodman@math.uiowa.edu

This material may be freely copied and used for non-commercial purposes. Please retain this author's notice, and do not distribute any altered version of this material without the author's permission  (unless  the material is altered beyond recognition).

You can use Mathematica  first of all as an advanced scientific calculator,  
more or less right out of the box.  You will need to know a little basic syntax. 
Double click on the following closed cell groups to read more.

A little syntax

Addition and subtraction are indicated with + and -.  Division is indicated with /.  Multiplication is indicated with *, or just by juxtaposition of expressions. Note however that you have to leave spaces sometimes to delimit expressions: x x  is interpreted as x times x, but xx is interpreted as a new variable called xx.

10 10 x x
10 10 xx

Powers are indicated by ^.  x^2 means x squared.

Expressions are grouped with round parentheses (never square brackets or curly brackets --- these have other uses).  

When in doubt, use parentheses!

Application of functions is always indicated by square brackets, and built-in Mathatica functions are always capitalized. For example you have to write Sin[x], and not sin(x).

Sin[π]
Sin π

You can enter mathematical notation such as ((∑_(n=1)^(∞1))/(n^2)) by using "palletes" to access the special notation.  Refer to the Mathematica documentation for further information.

Numerical results

Mathematica will do exact rational arithmetic, or leave expressions in symbolic form, also sometimes when you don't expect this.  To get (approximate) numerical results, you use the function N[ ].

Sin[2]
N[Sin[2]]

If an expression already involves a "floating point" number, the result will be given  numerically.

Sin[2.0]

The following calculates the sum of the reciprocals of the first 100 integers. You can see that sometimes exact rational arithmetic can be a little cumbersome!

(∑_(n=1)^100)(1/n)
N[(∑_(n=1)^100)(1/n)]

You can determine the number of decimal places displayed in numerical computations as follows.  The default is 6.

1000 N[(∑_(n=1)^100)(1/n)]
N[1000 (∑_(n=1)^100)(1/n),15]

The symbox % stands for the last computed result.  It is convenient for changing the form of the last computation without doing the computation over again.

1000 N[(∑_(n=1)^100)(1/n)]
N[%,15]

Common Mathematical Constants

The  ratio of the diameter of a circle to twice the radius is denoted Pi. The base of the natural logarithm  is denoted E. The complex square root of -1 is denoted I.

N[π]
N[E]
Solve[(x^2)+x+1==0,x]

Surprisingly,  Mathematica  does not regard Pi and E as numbers, but I is a number.

?NumberQ
NumberQ[3.45]
NumberQ[π]
NumberQ[I]

Common Mathematical Functions

The triginometric functions are
 
Sin[ ], Cos[ ], Tan[ ], Cot[ ],  Sec[  ],  Csc[ ]

N[((Sin[(π/7)])/(Cos[(π/7)]))]
N[Tan[(π/7)]]

The natural exponential function is Exp[x],  or E^x.

Exp[2.2]
(E^2.2)

Log[  ]  denotes the natural logarithm  (base E).

Log[10.]

You can get information on any built-in Mathematica function by using  the ?  operation.

?Log

You  can see from this that to get the common logarithm (base 10), you use Log[10, x].

Log[10,1000]

Abs[ ]  gives absolute value.  Sqrt[x]  or x^(1/2)  gives square root. Factorial[n]  or n!  gives the factorial of an integer.  

The inverse trigonometric functions are denoted by ArcSin[  ],  etc.   The ? operation does not give any information on the range of the functions, so you'll have to  resort to experimentation or the printed documentation.

?ArcSin

ArcSin[Sin[((3 π)/4)]]
ArcSin[Sin[((5 π)/4)]]