# Some Basic Mathematica(Introduction)

Simple Mathematica calculations

In your notebook, type

`   (1 + 2) * 3`

and press Enter. You’ll get the result:

`   9`

You can omit the multiplication sign, and Mathematica is smart enough to know that it is implied:

```   (1 + 2) 3
9```

But Mathematica can do a lot more than simple integer math. Try

`   102 / 9`

You get the result

`   34 / 3`

You see that Mathematica reduced the fraction to its simplest form by cancelling out common factors in the numerator and denominator. Also, notice that the result is still expressed as a fraction, not as a decimal number. This is because the fraction is more exact than any decimal approximation to it, and Mathematica tries to maintain as much accuracy as possible unless you specify otherwise.

To get a numerical approximation to this result, type

`   N[102 / 9]`

You’ll get the result

`   11.3333`

The N[…] command tells Mathematica to evaluate the quantity in brackets numerically. If we want more decimal places, we can ask Mathematica to calculate the same thing to 20 digits:

```   N[102 / 9, 20]
11.333333333333333333```

At this point, it’s useful to introduce a Mathematica shortcut that lets us take the previous output cell and include it in the current input cell. Enter

`   102 / 9`

and you’ll get the standard Mathematica result:

`   34 / 3`

Then enter in a new input cell

`   N[%, 20]`

and you’ll get the result

`   11.333333333333333333`

just as before. The % symbol tells Mathematica to insert the output of the previous calculation.

Mathematica knows the basic mathematical functions like sine and cosine. Typically these functions have the name you would expect, but with their first letter capitalized. To take the sine of 34/3 radians, enter

`   Sin[%]`

and you’ll get the result

`   -0.9434996270154848971`

Notice that Mathematica has kept 20 significant figures; it remembers that that was the accuracy of the previous output cell and passes that information along to the current cell.

If we try to compute the sine of 34/3 radians from scratch, we don’t get the same result:

```   Sin[102 / 9]
Sin[34 / 3]```

Here Mathematica has left both the fraction and the sine function unevaluated. To evaluate this numerically, we can use the N[…] command:

```   N[%, 20]
-0.9434996270154848971```

Notice that Mathematica uses square brackets to delimit the argument of a function, instead of the more conventional parentheses. This is because parentheses are used exclusively for grouping in Mathematica, as in the calculation we entered at the beginning of this section:

`   (1 + 2) * 3`

## Plotting lists of (x, y) points

We’ve seen that Mathematica uses parentheses for grouping and square brackets in functions. Mathematica uses curly braces to delimit lists of numbers. For example, a list of the first ten prime numbers would be

`   {2, 3, 5, 7, 11, 13, 17, 19, 23, 29}`

If you enter this as Mathematica input, you’ll get the exact same list as output:

`   {2, 3, 5, 7, 11, 13, 17, 19, 23, 29}`

This is because we haven’t asked Mathematica to do anything to the list. Later on we’ll see how we can use lists of numbers in calculations.

The reason we want to discuss lists now is that Mathematica represents (x, y) points as lists of two numbers. For example the point (x = 1, y = 3.7) is represented in Mathematica as

`   {1, 3.7}`

Suppose we have a list of three (x, y) points: (1, 2), (2, 3), and (3, 5). These points are represented as lists of two numbers. The list of the three points is then a nested list, or a list of lists:

`   { {1, 2}, {2, 3}, {3, 5} }`

To plot a graph of these three points, we use a new Mathematica command:

`   ListPlot[ { {1, 2}, {2, 3}, {3, 5} } ]`

This tells Mathematica to plot the list of points inside the square brackets. The spaces are optional and are included here mainly for the sake of clarity.

To plot ten points representing the first ten prime numbers, we would therefore type

```   ListPlot[ { {1, 2}, {2, 3}, {3, 5}, {4, 7},
{5, 11}, {6, 13}, {7, 17}, {8, 19},
{9, 23}, {10, 27} } ]```

Again, the extra space is optional. If you type the input as it is shown here, however, you’ll notice that your input cell grows large enough to accomodate all three lines of the command. If you forget a curly brace (or add an extra one), Mathematica will inform you of this. One of the points may be hard to see; look closely at the origin of the x and y axes to convince yourself that there is a point there.

Now let’s join the points with straight line segments. Type

```   ListPlot[ { {1, 2}, {2, 3}, {3, 5}, {4, 7},
{5, 11}, {6, 13}, {7, 17}, {8, 19},
{9, 23}, {10, 27} }, PlotJoined -> True ]```

The modifier

`   PlotJoined -> True`

tells Mathematica to connect the points with lines.

Here’s another shortcut that can save you a lot of typing. Suppose we wanted to store the list of the first ten primes in memory, so that we don’t have to type it in every time we want to use it. Enter

```   primes = { {1, 2}, {2, 3}, {3, 5}, {4, 7},
{5, 11}, {6, 13}, {7, 17}, {8, 19},
{9, 23}, {10, 27} }```

Mathematica will respond with

```   { {1, 2}, {2, 3}, {3, 5}, {4, 7},
{5, 11}, {6, 13}, {7, 17}, {8, 19},
{9, 23}, {10, 27} }```

This list is now stored in the variable “primes”. We can use this variable in a ListPlot command as follows:

`   ListPlot[primes, PlotJoined -> True]`

It’s good stylistic practice to give your own variables names that begin with lowercase letters. This prevents us from trying to use the name of a Mathematica command or function as a variable name. Mathematica commands are all case specific, which means that uppercase and lowercase letters are distinct.

If you just want to see what is stored in the variable primes, type

`   primes`

and Mathematica will respond with

```   { {1, 2}, {2, 3}, {3, 5}, {4, 7},
{5, 11}, {6, 13}, {7, 17}, {8, 19},
{9, 23}, {10, 27} }```

## Plotting functions such as y = f(x)

Suppose we want Mathematica to plot the function y = x**2 over the range of x values 0 < x < 10. Enter

`   Plot[x^2, {x, 0, 10}]`

and you’ll get such a plot. (Note that Mathematica uses the ^ character to indicate raising a number to a power.)

The Plot command can be used to plot virtually any one-dimensional function:

`   Plot[Sin[ x + 1/x ], {x, 0.5, 5}]`

Let’s take this command apart to see how its components work together.

The command takes two arguments, which are (in order) the function we want to plot and the range of x values we want to use:

`   Plot[ <function>, <range> ]`

The range is expressed as a list with three elements: the first element is the variable that will be plotted on the horizontal axis; the second element is the lower limit on this variable; and the third element is the upper limit on this variable.

The fact that the independent variable is specified as part of the plotting range means that we can call the independent variable anything we like:

`   Plot[Sin[time], {time, 0, 4 Pi}]`

(Note that Mathematica has memorized the value of pi. You just have to remember that the letter P is capitalized.)

## Combining two or more plots

Mathematica lets you store plots in variables so that you can combine several individual plots in a composite figure. Enter

```   splot = Plot[ Sin[x], {x, 0, 2 Pi} ]
cplot = Plot[ Cos[x], {x, 0, 2 Pi} ]```

and you will get two individual plots of the sine and cosine function. To plot both functions on the same set of axes, enter

`   Show[splot, cplot]`

You can combine different types of plots in this fashion. For example, you might want to combine a plot of experimental data points with a plot of a curve that fits through these points. The data points could be plotted with aListPlot command, and the curve with a Plot command. Then the Show command would combine these two plots.

Sometimes you will generate a plot, and after looking at it, decide that you want to save it in a variable so that you can combine it with another plot. To do this, you can use the % shortcut we already mentioned. For example,

```   Plot[ Sin[x], {x, 0, 2 Pi} ]
splot = %```

will store the plotted sine curve in the variable splot.

The Show command will combine several plots at once:

```   splot = Plot[ Sin[x], {x, 0, 2 Pi} ]
cplot = Plot[ Cos[x], {x, 0, 2 Pi} ]
tplot = Plot[ Tan[x], {x, 0, 2 Pi} ]
Show[splot, cplot, tplot]```

Or you can combine the plots in stages:

```   splot = Plot[ Sin[x], {x, 0, 2 Pi} ]
cplot = Plot[ Cos[x], {x, 0, 2 Pi} ]
sandc = Show[splot, cplot]
tplot = Plot[ Tan[x], {x, 0, 2 Pi} ]
Show[sandc, tplot]```

When you combine two or more plots, you may want to adjust the limits of the x and y axes to focus attention on a particular region of the plot. The PlotRange modifier to the Show command lets you do this. Enter

```   Show[splot, cplot, tplot,
PlotRange -> { {0, 10}, {-10, 10} }]```

This tells Mathematica to extend the horizontal axis so that it includes the range 0 < x < 10 and the vertical axis so that it includes the range -10 < y < 10. The general format for the PlotRange modifier is

`   PlotRange -> { { <Xmin>, <Xmax> }, { <Ymin>, <Ymax> } }`

You can see that the range is specified as a nested list, but not as a list of two (x, y) points.

Note that when we changed the axis limits, Mathematica did not extend the plots across the entire x axis. If you want the curves to extend all the way to x = 10, you need to specify this in the original Plot commands:

```   splot = Plot[ Sin[x], {x, 0, 10} ]
cplot = Plot[ Cos[x], {x, 0, 10} ]
tplot = Plot[ Tan[x], {x, 0, 10} ]
Show[splot, cplot, tplot,
PlotRange -> { {0, 10}, {-10, 10} }]```

## Fitting data points to polynomial expressions

Suppose we have a set of experimental data that we want to fit with a straight line. For specificity, imagine that we have measured absorbance as a function of concentration in a test of the Beer-Lambert law:

```   concentration (M)     absorbance

0.01                0.095
0.02                0.202
0.04                0.413
0.06                0.629
0.10                1.101
0.15                1.735```

First let’s put this data into a list of (x, y) points:

```   data = { {0.01, 0.095}, {0.02, 0.202}, {0.04, 0.413},
{0.06, 0.629}, {0.10, 1.101}, {0.15, 1.735} }```

We can plot the data with

`   ListPlot[data]`

from which we see that the data looks fairly linear at low concentrations, but starts to curve upward as the concentration increases. (Well, it’s actually a bit hard to see this, but it will become more evident once we try to fit the data with a straight line.)

To fit the data to a straight line, type

`   Fit[data, {1, conc}, {conc}]`

This tells Mathematica to fit the data in terms of two functions of the variable conc; these functions are 1 and conc. You should get the result

`   -0.044375 + 11.6875 conc`

from which we see that the slope and y-intercept of the line are 11.6875 and -0.044375, respectively. (Note that Mathematica uses its default of six significant figures even though our data has fewer significant figures.)

The general form of the Fit command is:

`   Fit[ <data-list>, <function-list>, <variable-list> ]`

The first argument is a list of (x, y) data points, in the standard Mathematica form of a nested list. The second argument is a list of functions that Mathematica will use to try to fit the points. The third argument is a list of the independent variables in the data set. In this example, we have only one independent variable, so the variable list is a list with one element: the variable conc. (Of course, we could name the independent variable anything we want, as long as the same name appears in the list of functions and the list of variables.) Later we’ll see how we can fit data as a function of two or more independent variables.

You might be asking yourself, “Why is there a 1 in the list of functions?” Good question! Let’s try leaving the 1 out:

```   Fit[data, {conc}, {conc}]
11.2461 conc```

Here we have instructed Mathematica to fit the data to a straight line that goes through the origin. The 1 in the variable list is used to fit the y-intercept in our original example. Think of the fit as finding the best constants A and B such that the data is described by the line

`   A * 1 + B * conc`

When we leave out the 1, we are telling Mathematica not to look for a constant term in the fitting equation. This is equivalent to finding the best constant B such that the data is described by the line

`   B * conc`

with A implicitly set to zero.

In the example presented here, we might want to force the y-intercept to be zero; after all, that is the sensible Beer-Lambert law prediction. But if our apparatus is dirty or malfunctioning, it may register a “baseline” absorbance even when there is nothing in our sample cell. This would show up as a constant error in the absorbance, independent of concentration. So the fit to the line

`   A * 1 + B * conc`

lets us estimate this error. Notice that the slopes of the two straight lines are slightly different.

As we mentioned in class, the Beer-Lambert law can break down at high concentrations. Let’s add a quadratic term to our fitting equation to see if the data is described better that way:

```   linfit = Fit[data, {1, conc}, {conc}]
-0.044375 + 11.6875 conc
quadfit = Fit[data, {1, conc, conc^2}, {conc}]
-0.00325599 + 9.91865 conc + 11.1374 conc^2```

Now let’s plot both fits, along with the experimental data:

```   points = ListPlot[data]
curve1 = Plot[linfit, {conc, 0, 0.15}]
curve2 = Plot[quadfit, {conc, 0, 0.15}]
Show[points, curve1]
Show[points, curve2]```

We see that the quadratic curve does seem to fit the data better. In addition, the quadratic fit leads to a y-intercept which is much closer to zero, in accord with our intuition.

## Generating and manipulating lists of numbers

The Table command can be used to generate a list of numbers using a predefined mathematical expression. Suppose, for example, that we want to make a list of the squares of the numbers from 1 to 10. This command will generate such a list:

```   Table[ n^2, {n, 1, 10} ]
{ 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 }```

The general format of the Table command is

`   Table[ <expression>, <iterator> ]`

where <iterator> tells Mathematica what sequence of numbers to use in generating the list from <expression>. In this example, the iterator

`   {n, 1, 10}`

indicates that the variable n will go from 1 to 10.

The loop variable does not have to be an integer. A list of evenly spaced numbers in the interval between 0 and 1 can be generated by

```   Table[ x, {x, 0, 1, 0.01} ]
{ 0, 0.01, 0.02, ..., 0.99, 1 }```

Here the iterator

`   {x, 0, 1, 0.01}`

indicates that the lower limit on the variable x is 0, the upper limit is 1, and the interval between successive values of x is 0.01.

By using more complicated expressions in the Table command, we can generate lists of (x, y) points to be used in ListPlot. Try

```   sine = Table[ {x, Sin[x]}, {x, 0, 2 Pi, Pi/100} ]
ListPlot[sine]```

In this example, the expression used to construct the list is itself a list. So the end result is a nested list of (x, y) points suitable for plotting with ListPlot.

So now we know how to build lists. What about taking lists apart? Define a simple list of five numbers:

```   list = Table[2^n, {n, 0, 4}]
{ 1, 2, 4, 8, 16 }```

To pick out the fourth item in this list, we type

```   list[]
8```

The double brackets are Mathematica’s way of extracting a single element from a list of items.

Now suppose we have a list of three (x, y) points:

```   data = Table[ {n, 3^n}, {n, 0, 2} ]
{ {0, 1}, {1, 3}, {2, 9} }```

This is a nested list of three two-element lists, each representing a single (x, y) data point. To get the third point, we type

```   data[]
{2, 9}```

Mathematica gives us the third element of the list, which is itself a list of two numbers. To get just the y coordinate of this point, type

```   data[[3, 2]]
9```

Here we have two numbers in brackets, which we can think of as indices into the nested list. Basically we are asking Mathematica to take the third element of the original list, and then take the second element of this sub-list.

## Complex numbers in Mathematica

Mathematica uses the capital letter I to represent the square root of -1. Type

`   Sqrt[-1]`

and you’ll get the answer

`   I`

You can use I in expressions: the complex number 2 + 3i is represented as

`   2 + 3 I`

in Mathematica. The generic complex number (x + y i) is written as

`   x + y I`

or, equivalently,

`   x + I y`

Mathematica has a tendency to “alphabetize” things, so it will usually print out (x + y i) in the second form.

Mathematica uses the function Conjugate to take the complex conjugate of a number. Try it:

```   a = 2 + 3 I
Conjugate[a]
2 - 3 I```

We know that the complex conjugate of (x + y i) is (x – y i). But Mathematica gives us

```   Conjugate[x + y I]
Conjugate[x + I y]```

which, needless to say, is not very informative.

The problem is that we have not specified whether x and y are real or complex numbers, and Mathematica won’t make any assumptions about x and y without our help. If x and y are themselves complex numbers, then the conjugate of (x + y i) is not simply (x – i y). To tell Mathematica that x and y are real numbers, use the ComplexExpand command:

```   ComplexExpand[ Conjugate[x + y I] ]
x - I y```

Now we get the expected result. Remember to use ComplexExpand when working with complex functions like wavefunctions.

## Derivatives and integrals in Mathematica

Mathematica uses the command D[…] to take derivatives of variables and functions. As an example, type

```   D[x^3, x]
3 x^2```

The general format of the D[…] command is

`   D[ <function>, <variable> ]`

which tells Mathematica to take the derivative of <function> with respect to <variable>. Mathematica treats all derivatives as partial derivatives, so we have

```   D[x y^2, x]
y^2
D[x y^2, y]
2 x y```

To take the second derivative, we can just use the D[…] command twice in a row:

```   D[ D[x^3, x], x ]
6 x```

The command to compute integrals is Integrate. It works much like D[…] in that we specify an integrand and a variable of integration:

```   Integrate[x^2, x]
x^3 / 3
Integrate[x y, y]
x y^2 / 2```

Note that Mathematica omits the constant of integration that is so common in calculus textbooks.

We can also use Integrate to compute definite integrals by specifying a lower and upper limit of integration:

```   Integrate[x^2, {x, 1, 2}]
7 / 3```

computes the integral of x^2 from x = 1 to x = 2. The special keyword Infinity can be used to specify a lower or upper limit of integration:

```   Integrate[(1/x)^2, {x, 1/2, Infinity}]
2```

Some definite integrals are too hard for Mathematica to compute analytically. In this case, we can estimate the integral numerically using NIntegrate. (Note the double capital letter at the beginning of this command.) As an example, try

```   Integrate[Sin[x^4], {x, 0, 1}]
Integrate[Sin[x^4], {x, 0, 1}]```

You see that when an integral is too hard for Mathematica, it simply “spits it out”. But we can compute the integral numerically:

```   NIntegrate[Sin[x^4], {x, 0, 1}]
0.18757```

Another way to integrate numerically is to nest the Integrate command within the N[…] command:

```   N[ Integrate[Sin[x^4], {x, 0, 1}] ]
0.18757```

This has the advantage that we can ask for more significant figures:

```   N[ Integrate[Sin[x^4], {x, 0, 1}], 20]
0.187569544685```

Note that we don’t get 20 significant figures because numerical integration is inherently approximate. In this case we only got 18 significant figures. When integrating numerically, you usually need to ask for a few more significant figures than you really want.

## Special functions in Mathematica

Here is a list of various functions that Mathematica has already defined for you. This page will grow as the semester continues.

Trigonometric functions:

• Sin[x] gives the sine of x in radians.
• Cos[x] gives the cosine of x in radians.
• Tan[x] gives the tangent of x in radians.

Exponentiation and logarithms:

• Exp[x] gives e to the power x.
• Log[x] gives the natural logarithm of x.

Square roots:

• Sqrt[x] gives the square root of x.

## Contour and surface plots in Mathematica

Mathematica can make very nice contour and surface plots of three-dimensional functions such as z = z(x, y). The commands that generate these plots are ContourPlot and Plot3D for contour and surface plots, respectively.

These commands have the same basic form, although there are more “options” for Plot3D. To make a plot of some function of x and y in which x ranges from xmin to xmax and y ranges from ymin to ymax, enter

`   ContourPlot[ <function>, {x, <xmin>, <xmax>}, {y, <ymin>, <ymax> ]`

or

`   Plot3D[ <function>, {x, <xmin>, <xmax>}, {y, <ymin>, <ymax> ]`

For example, a contour plot of the function Exp[-(x^2 + 3 y^2)] near the origin can be generated as follows:

`   ContourPlot[ Exp[-(x^2 + 3 y^2)], {x, -2, 2}, {y, -2, 2} ]`

A three-dimensional surface plot of the same function is generated with the command

`   Plot3D[ Exp[-(x^2 + 3 y^2)], {x, -2, 2}, {y, -2, 2} ]`

If you try these commands, you might find that the surface plot seems “chopped off” near the origin. We can rectify this by including a larger range of z coordinates in the plot, using the PlotRange option that we first saw in two-dimensional plots:

```   Plot3D[ Exp[-(x^2 + 3 y^2)], {x, -2, 2}, {y, -2, 2},
PlotRange -> {0, 2} ]```

This command tells Mathematica to include all parts of the function with z values between 0 and 2. We can also use the PlotRange option to specify boundaries on all three coordinates, for example to zoom into a portion of the surface:

```   Plot3D[ Exp[-(x^2 + 3 y^2)], {x, -2, 2}, {y, -2, 2} ]
Show[ %, PlotRange -> {{0, 1}, {0, 1}, {0, 2}} ]```

You might notice that the resolution in this “zoomed” plot is fairly poor. Mathematica creates surface plots by scanning over a rectangular grid of points and calculating the height of the surface at each point. When we zoom in, Mathematica continues to use the original grid of points. We can make the grid finer by using the PlotPoints option in Plot3D. (Note that this option does not work in the Show command!) Here is how we might increase the resolution of this zoomed plot:

```   Plot3D[ Exp[-(x^2 + 3 y^2)], {x, -2, 2}, {y, -2, 2}, PlotPoints-> 30 ]
Show[ %, PlotRange -> {{0, 1}, {0, 1}, {0, 2}} ]```

Of course, if you decided to zoom in after viewing a surface plot, you can combine the PlotPoints and PlotRange options in the Plot3D command to do everything in one step:

```   Plot3D[ Exp[-(x^2 + 3 y^2)], {x, -2, 2}, {y, -2, 2}, PlotPoints-> 30,
PlotRange -> {{0, 1}, {0, 1}, {0, 2}} ]```

Even this is wasteful in a sense; we are generating a 30-by-30 grid of points in which x and y both range from -2 to 2, and then throwing away all of the points except those where x and y are between 0 and 1. Instead, we might try

```   Plot3D[ Exp[-(x^2 + 3 y^2)], {x, 0, 1}, {y, 0, 1}, PlotPoints-> 30,
PlotRange -> {0, 2} ]```

which gives us higher resolution in the region of interest.

The PlotPoints option applies to contour plots as well. Compare these two plots:

```   ContourPlot[ Exp[-(x^2 + 3 y^2)], {x, -2, 2}, {y, -2, 2} ]

ContourPlot[ Exp[-(x^2 + 3 y^2)], {x, -2, 2}, {y, -2, 2},
PlotPoints -> 30 ]```

The plot with more points is much smoother, and represents the oval shape of the surface more faithfully. But how can we get rid of the shades of gray so that we can see the contours better? Try

```   ContourPlot[ Exp[-(x^2 + 3 y^2)], {x, -2, 2}, {y, -2, 2},
PlotPoints -> 30, ContourShading -> False ]```

Nice, isn’t it? The only problem is that we don’t know what z values the contour lines correspond to. With the Contours option we can specify exactly where we want the contours. Try entering

```   ContourPlot[ Exp[-(x^2 + 3 y^2)], {x, -2, 2}, {y, -2, 2},
PlotPoints -> 30, ContourShading -> False,
Contours -> {0.2, 0.4, 0.6, 0.8},
PlotRange -> {0, 2} ]```

to see how you can control the placement of contour lines. Note that we need to include both the Contours and the PlotRange options to make sure that all of the contour values fit inside the range of z values that Mathematica will plot. Remember that when you only give one pair of numbers for PlotRange, Mathematica applies this range to the z axis.

Finally, note that the variables x and y could be called anything we want. These two commands produce exactly the same results:

```   ContourPlot[ Exp[-(x^2 + 3 y^2)], {x, -2, 2}, {y, -2, 2} ]

ContourPlot[ Exp[-(u^2 + 3 v^2)], {u, -2, 2}, {v, -2, 2} ]```

# Oh MY GOD! Mathematica

What took me this long to study mathematica.

If you love yourself and a computer and programming, mathematica shouldnt be option as you consider what to add to your programming capability toolbox.

Today i extract some files from wikipedia for you to have A glimpse of mathematica.

MATHEMATICA

# Mathematica

For other uses, see Mathematica (disambiguation).
Mathematica  Mathematica 8.0.0 Linux frontend
Developer(s) Wolfram Research
Initial release June 23, 1988
Stable release 8.0.1  (7 March, 2011) [+/−]
Preview release [+/−]
Written in Mathematica, C
Platform Cross-platform (list)
Available in English, Chinese and Japanese.
Type Computer algebranumerical computations,Information visualizationstatisticsuser interface creation
License Proprietary
Website www.wolfram.com/products/mathematica

Mathematica is a computational software program used in scientific, engineering, and mathematical fields and other areas of technical computing. It was conceived by Stephen Wolfram and is developed by Wolfram Research of Champaign, Illinois.

## Features

Features of Mathematica include:

## Interface

Mathematica is split into two parts, the kernel and the front end. The kernel interprets expressions (Mathematica code) and returns result expressions.

The front end, designed by Theodore Gray, provides a GUI, which allows the creation and editing of Notebook documents containing program code with prettyprinting, formatted text together with results including typeset mathematics, graphics, GUI components, tables, and sounds. All contents and formatting can be generated algorithmically or interactively edited. Most standard word processing capabilities are supported, but there is only one level of “undo”.

Documents can be structured using a hierarchy of cells, which allow for outlining and sectioning of a document and support automatic numbering index creation. Documents can be presented in a slideshow environment for presentations. Notebooks and their contents are represented as Mathematica expressions that can be created, modified or analysed by Mathematica programs. This allows conversion to other formats such as TeX or XML.

The front end includes development tools such as a debugger, input completion and automatic syntax coloring.

The standard front end is used by default, but alternative front ends are available. They include the Wolfram Workbench, an Eclipse basedIDE, introduced in 2006. It provides project-based code development tools for Mathematica, including revision management, debugging, profiling, and testing. Mathematica also includes a command line front end.

## High-performance computing

In recent years, the capabilities for high-performance computing have been extended with the introduction of packed arrays (version 4, 1999), sparse matrices (version 5, 2003), and by adopting the GNU Multi-Precision Library to evaluate high-precision arithmetic.

Version 5.2 (2005) added automatic multi-threading when computations are performed on multi-core computers. This release included CPU specific optimized libraries. In addition Mathematica is supported by third party specialist acceleration hardware such as ClearSpeed.

In 2002, gridMathematica was introduced to allow user level parallel programming on heterogeneous clusters and multiprocessor systems  and in 2008 parallel computing technology was included in all Mathematica licenses including support for grid technology such as Windows HPC Server 2008Microsoft Compute Cluster Server and Sun Grid.

Support for CUDA and OpenCL GPU hardware was added in 2010. Also, version 8 can generate C code, which is automatically compiled by a system C compiler, such as Intel C++ Compiler or compiler of Visual Studio 2010.

## Development

Several solutions are available for deploying applications written in Mathematica:

Mathematica Player Pro is a runtime version of Mathematica that will run any Mathematica application but does not allow editing or creation of the code. A free version, Wolfram CDF Player is provided for running Mathematica programs that have been saved in the CDF format. It can also view standard Mathematica files, but not run them.

webMathematica allows a web browser to act as a front end to a remote Mathematica server. It is designed to allow a user written application to be remotely accessed via a browser on any platform. It may not be used to give full access to Mathematica.

Mathematica code can be converted to C code or to an automatically generated DLL.

## Connections with other applications

Communication with other applications occurs through a protocol called MathLink. It allows communication between the Mathematica kernel and front-end, and also provides a general interface between the kernel and other applications.

Although Mathematica has a large array of functionality, a number of interfaces to other software have been developed, for use where other programs have functionality that Mathematica does not provide, to enhance those applications, or to access legacy code.

Wolfram Research freely distributes a developer kit for linking applications written in the C programming language to the Mathematica kernel through MathLink.

Using .NET/Link., a .NET program can ask Mathematica to perform computations; likewise, a Mathematica program can load .NET classes, manipulate .NET objects and perform method calls. This makes it possible to build .NET graphical user interfaces from within Mathematica. Similar functionality is achieved with J/Link., but with Java programs instead of .NET programs.

Communication with SQL databases is achieved through built-in support for JDBC. Mathematica can also install web services from a WSDL description.

Other languages that connect to Mathematica include Haskell, AppleScript, Racket, Visual Basic, Python and Clojure.

Links are available to many specialized mathematical software packages including OpenOffice.org Calc, Microsoft Excel, MATLAB, R, Sage, SINGULAR, MathModelica andOrigin.

Mathematical equations can be exchanged with other computational or typesetting software via MathML.

Mathematica can capture real-time data via a link to LabView, from financial feeds  and directly from hardware devices via GPIB (IEEE 488), USB and serial interfaces. It automatically detects and reads from HID devices.

Alternative interfaces are available such as JMath, based on GNU readline and MASH which runs self contained Mathematica programs (with arguments) from the UNIX command line.

## Computable data

Mathematica includes collections of curated data in a consistent framework for immediate computation. Data can be accessed programmatically to inform or test models and is updated automatically from a data server at Wolfram Research. Some data such as share prices and weather are delivered in real-time. Data sets currently include:

• Astronomical data: 99 properties of 155,000 astronomical bodies
• Chemical data: 111 properties of 34,000 chemical compounds, 86 properties of 118 chemical elements and 35 properties of 1000 subatomic particles
• Geopolitical data: 225 properties of 237 countries and 14 properties of 160,000 cities around the world
• Financial data: 71 historical and real-time properties of 186,000 shares and financial instruments
• Mathematical data: 89 properties of 187 polyhedra, 258 properties of 3000 graphs, 63 properties of 6 knots, 37 properties of 21 lattice structures, 32 properties of 52 geodesic schemes
• Language data: 37 properties of 149,000 English words. 26 additional language dictionaries
• Biomedical data: 41 properties of all 40,000 human genes, 30 properties of 27,000 proteins
• Weather data: live and historical measurements of 43 properties of 17,000 weather stations around the world
• Wolfram|Alpha data: trillions of data points from WolframAlpha

## Licensing

Mathematica is proprietary software restricted by both trade secret and copyright law.

A regular single-user license for Mathematica used in a commercial environment costs \$2495. It includes four additional kernels for parallel computations and one year of service that includes updates, technical support, a home use license, a webMathematica Amateur license, a Wolfram Workbench license and three Mathematica Player Pro licenses. Discounts are available for government, charity, educational, pre-college, school, student, home use and retiree use and depend on geographical region. Student licenses cost \$140. A general “home use” license (“Mathematica Home Edition”) is also available to the public and is priced at \$295. Educational site licenses allow use by students at home. A license manager similar to FLEXnet is available to provide sharing of licenses within a group.

## Platform availability

Mathematica 8 is supported on various versions of Linux, Apple’s Mac OS X, and NT-based Microsoft Windows. All platforms are supported with 64-bit implementations. Earlier versions of Mathematica up to 6.0.3 supported other operating systems, including Solaris , AIXConvexHP-UXIRIXMS-DOSNeXTSTEPOS/2Ultrix and Windows Me.

## Version history

Mathematica built on the ideas in Cole and Wolfram’s earlier Symbolic Manipulation Program (SMP).

Wolfram Research has released the following versions of Mathematica:

• Mathematica 1.0 (June 23, 1988)
• Mathematica 1.1 (1989)
• Mathematica 1.2 (August 1, 1989)
• Mathematica 2.0 (January 15, 1991)
• Mathematica 2.1 (June 15, 1992)
• Mathematica 2.2 (June 1, 1993)
• Mathematica 3.0 (September 3, 1996)
• Mathematica 4.0 (May 19, 1999)
• Mathematica 4.1 (November 2, 2000)
• Mathematica 4.2 (November 1, 2002)
• Mathematica 5.0 (June 12, 2003)
• Mathematica 5.1 (October 25, 2004)
• Mathematica 5.2 (June 20, 2005)
• Mathematica 6.0 (May 1, 2007)
• Mathematica 6.0.1 (July 5, 2007)
• Mathematica 6.0.2 (2008)
• Mathematica 6.0.3 (2008)
• Mathematica 7.0 (November 18, 2008)
• Mathematica 7.0.1 (March 5, 2009)
• Mathematica 8.0 (November 15, 2010)
• Mathematica 8.0.1 (March 7, 2011)

## See also Wikibooks has a book on the topic of Mathematica Wikimedia Commons has media related to: Mathematica

## References

1. ^ http://blog.wolfram.com/2008/06/23/mathematica-turns-20-today/
2. ^ Stephen Wolfram: Simple Solutions; The iconoclastic physicist’s Mathematica software nails complex puzzles, BusinessWeek, October 3, 2005.
3. ^ Wolfram Research Contact Info
4. ^ Mathematica documentation
5. ^ Review: Mathematica 7. Technical computing powerhouse gets more oomph Macworld, Jan 2009
6. ^ Mathematica 6 Labs Review Cadalyst Feb 1, 2008
7. ^ The Free-Form Linguistics Revolution in Mathematica
8. ^ MacWorld review of Wolfram Workbench
9. ^ Using a Text-Based Interface documentation at wolfram.com
10. ^ Math software packs new power; new programs automate such tedious processes as solving nonlinear differential equations and converting units by Agnes Shanley, Chemical Engineering, March 1, 2002.
11. ^ Mathematica 5.1: additional features make software well-suited for operations research professionals by ManMohan S. Sodhi, OR/MS Today, December 1, 2004.
12. ^ The 21st annual Editors’ Choice Awards, Macworld, February 1, 2006.
13. ^ ClearSpeed Advance(TM) Accelerator Boards Certified by Wolfram Research; Math Coprocessors Enable Mathematica Users to Quadruple Performance.
14. ^ gridMathematica offers parallel computing solution by Dennis Sellers, MacWorld, November 20, 2002.
15. ^ Mathematica Player Pro – new Application Delivery System for Mathematica www.gizmag.com
16. a b New Mathematica: faster, leaner, linkable and QuickTime-compatible: MathLink kit allows ties to other apps. (Wolfram Research Inc. ships Mathematica 2.1, new QuickTime-compatible version of Mathematica software) by Daniel Todd, MacWeek, June 15, 1992.
17. ^ .NET/Link: .NET/Link is a toolkit that integrates Mathematica and the Microsoft .NET Framework.
18. ^ Mathematica 4.2 by Charles Seiter, Macworld, November 1, 2002.
19. ^ Mathematica 5.1 Available , Database Journal, Jan 3, 2005.
20. ^ Mathematical Web Services: W3C Note 1 August 2003
21. ^ Introduction to Web Services, Mathematica Web Services Tutorial
22. ^ Haskell pakages
23. ^ Unisoftware plus
24. ^ MrMathematica website
25. ^ Mathematica for ActivX
26. ^ Pythonika MathLink module for Python
27. ^ PYML (Python Mathematica interface)
28. ^ 
29. ^ CalcLink Lauschke Consulting
30. ^  Mathematica Link for Excel
31. ^ Mathematica Toolbox for Matlab
32. ^ Mathsource item #618 for calling MATLAB from Mathematica Roger Germundsson from Wolfram Research
33. ^ R-Link Calling R from within Mathematica
34. ^ Using R