Mathematica

“For more than 25 years, Mathematica has defined the state of the art in technical computing and provided the principal computation environment for millions of innovators, educators, students, and others around the world.”

Wolfram Demonstration Projects  http://demonstrations.wolfram.com/

Comprehensive Documentation http://reference.wolfram.com/language/

Mathematica Notebooks (*.nb)

When Mathematica is first started, it displays an empty notebook with a blinking cursor. You can start typing right away.

1+3+2*5

Mathematica by default will interpret your text as input. Type Shift+Return (it’s the same as Shift+Enter) to make Mathematica process your input. If your keyboard has a numeric keypad, you can use its Enter key instead of Shift+Return.

Mathematica will  label  your input with In[n]:=1+3+2*5. It labels the corresponding output Out[n]=14. Labels are added automatically and they reflect the order in which the input is evaluated by the Kernel. By default, input/output pairs are grouped using rectangular cell brackets displayed in the right margin.

All results are stored and you can use them in any following calculations as long as you do not quit Mathematica (more precisely the kernel). The percent sign % can be used to refer to the output of the last evaluation that Mathematica performed.

% 5

In[1]+6

Input Expressions

You can also use variables or put several commands, separated by semicolons, on one line. A semicolon also has the effect of suppressing the corresponding output.

x=5;  y=27; y +(x^3)

We can also write each command on a separate line (enter/return) within the same cell.

x=5
y=27;
y +(x^3)

Writing several commands not separated by semicolons on the same line can lead to different results. By default, a space between two expressions is interpreted as multiplication! Try writing something like x=5 27+x^3! What do you get?

Moreover, Mathematica is case sensitive!

X+x

Using Palettes

Here is one way to enter a particular expression.

2^10+1/2+Sqrt[2]

We can use the Palettes to typeset various basic commands and text. 
Select Palettes→Basic Math Assistant, or Palettes→Classroom Assistant. We can then write expressions like square roots (■^(1/□)) , integrals (∫_□^□)□d□  and many others, by simply using the predefined templates from the Palettes. The same mathematical expression from above can be written more elegantly as follows:

(2^10)+(1/2)+(Sqrt[2])

Symbolic versus Numeric Computations

Sin[2]

If you type in Sin[2], Mathematica just returns your input unevaluated. The reason is that we have specified an exact argument and Mathematica tries to find an exact solution in this case. Since there is no simpler exact expression for our input, Mathematica leaves it as it is. You can tell Mathematica that the input is not an exact number by adding a decimal point. Alternatively you can also use the N[..] command to get a numeric answer. In addition, this allows to give the number of digits you want as an optional argument.

Sin[2.]

N[Sin[2],100]

Notebooks as Documents

Mathematica notebooks are structured interactive documents that are organized into a sequence of cells. Each cell may contain text, graphics, sounds or Mathematica expressions in any combination. The extent of each cell is indicated by a bracket on the right.

Particularly in larger notebooks, it is common to have chapters, sections and so on, each represented by groups of cells. Having a structured document makes it easier later one to convert your notebook into a slide presentation. The  various  kinds of cells available are listed in Format->Style. The grouping of cells in a notebook is indicated by nested brackets on the right. Font, Color, Spacing and other properties of the appearance of cells can also be changed from Format.

Example of a Section

Subsection 1 (click Alt-Return to create below another cell of the same type)

Subsection II

This subsection has a lot of text and some numbered lists. The text is blue because this cell has not been properly formated to text, so Mathematica sees it as some sort of long command. As we continue to type in, Mathematica will suggest that we convert the cell to text or to free-form linguistic input.

Numbered list

And a sublist

.....

The first list continues here

Subsection III

Notebook Style

To change the style of a cell, click the cell bracket. The bracket is higlighted. Select a style from Format→Style. The cell will immediately reflect the change.

To change the overall look of a notebook, choose Format→Stylesheet. Select a stylesheet from the menu. All cells in the notebook will change appearance, based on the definitions in the new stylesheet.

Free-Form Input

Free-Form Input allows users to enter plain English and get immediate results, as well as the Mathematica correct input for further exploration—without the need for syntax.

In the beginning, you can learn Mathematica syntax by entering a query in plain English and then viewing the free-form queries translated in precise Mathematica commands.

Click on the Cell Insertion Assistant (+ Sign at the left) and choose Free-Form Input. Alternatively, click Insert->Inline Free Form Input. An orange square with an equal sign will appear in the cell. The cursor will be blinking to the right of the orange square.

After clicking Shift+Enter, we will see the command that Mathematica translated our free-form input into. You need to have an active Internet Connection to use Free-Form Input. Use the + Sign to the right of the Free-Form Input to show all results.

Getting Started with Mathematica
	Functions
	Conditional Statements(If, Switch)
	Loops (For, While, Do)
	Control structures (Break, Return)
	Objects (Graphs, Matrices, ...)

Functions

Mathematica has a large amount of functions already built in. The arguments of a function are put in between square brackets and separated by commas. Some basic functions are given below. Note that all built in functions and variables start with capital letters. To avoid potential conflicts it is a good idea to start your own functions and variables with lower case letters.

Sqrt[x]     square root (Sqrt[x])
                         Exp[x]     exponential (e^x)
                         Log[x]     natural logarithm (Subscript[log, e] x)
                     Log[b, x]     logarithm to base b (Subscript[log, b] x)
  Sin[x], Cos[x], Tan[x]     trigonometric functions 
   ArcSin[x], ArcTan[x]     inverse trigonometric functions                                    
                         Abs[x]     absolute value
                     Round[x]    closest integer to x

Round[Sqrt[Abs[-5]]+ArcSin[1/2]]

User defined functions

We can define our own functions as follows:

f[x_]:=(x^2)+Sin[x]

In this expression the underscore represents a pattern. A single underscore will match a single expression (argument) and x is the name of the pattern (it can be used to refer to the matched expression on the right hand side). The colon tells Mathematica not to evaluate the right hand side. It will only be evaluated when you invoke the function. This is why you get no output. Now you can use your function:

f[angle]+Pi

f[2Pi]

Try to assign some value to x, then compute f[2Pi]. What do you notice? Does f use the global or the local values of x when computing f[2Pi]?

x=5;
f[2Pi]

Warning:  Do not omit the colon when defining functions!

x=5;
g[x_]=(x^2)+Sin[x]
g[2Pi]

Can you explain this result? You can look at the definition of a function by using a question mark:

?f

?g