## Tutorial 1: Getting Started.

Tutorial 1: Getting Started.

Welcome to Mathematica!

◼

A taste of Mathematica’s capabilities

◼

Introduction to Notebooks

◼

Practicing getting help

◼

Exploring the documentation center

Click on the forward arrow above to move to the next slide.

This tutorial is based on and uses materials from Wolfram Mathematica 7's “Learn with guided examples”.

This tutorial is based on and uses materials from Wolfram Mathematica 7's “Learn with guided examples”.

## Using Mathematica as a calculator

Using Mathematica as a calculator

You can use Mathematica as a calculator.

◼

Move your cursor below this text until it becomes a horizontal cursor.

Then click your mouse button.

As soon as you start typing this will become a new input cell.

Then click your mouse button.

As soon as you start typing this will become a new input cell.

◼

Now, type in 2+2.

◼

Then press Shift+Enter (Hold down Shift and press Enter).

◼

You should see the answer appear.

Now try it again with something more complicated like 500! or 78^3.

Remember: To calculate an expression, you must use Shift+Enter.

Remember: To calculate an expression, you must use Shift+Enter.

## Editing cells

Editing cells

Here is how you can use Mathematica to create a plot of the trigonometric function .

Press Shift+Enter to evaluate and see the plot.

y=sin(x)+cos(3x)

Press Shift+Enter to evaluate and see the plot.

Plot[Sin[x]+Cos[3x],{x,0,4Pi}]

Out[]=

When you have existing input cells, it’s easy to edit them, just as you would in a word processor.

Try changing Cos[3x] to Cos[5x] in the Plot command above and press Shift+Enter to re-evaluate the input. The new output will replace the old.

Now try making some other changes to the input and see what happens.

A key to your success in this class will be exploring, experimenting, and not giving up when things don’t work right the first time.

## Keys to success: Capital Letters and [Square Brackets]

Keys to success: Capital Letters and [Square Brackets]

Now that you’ve learned how to get around in Mathematica, let’s look at the Mathematica language in more detail.

The most basic rule to know is that all built-in Mathematica functions start with CAPITAL LETTERS and enclose their arguments in [square, brackets].

Click in each of the following input cells and press Shift+Enter to see the result.

The most basic rule to know is that all built-in Mathematica functions start with CAPITAL LETTERS and enclose their arguments in [square, brackets].

Click in each of the following input cells and press Shift+Enter to see the result.

In[]:=

Plot[BesselJ[1,x],{x,0,30}]

Multiword function names use InternalCapitalization.

ListPlot[Table[Prime[n],{n,1,30}]]

Even standard math functions like sin and cos start with a capital letter.

Cos[0]

The constants , , and also use capital letters.

e

i

π

In[]:=

N[{E,I,Pi}]

Because of this strict rule, you are free to use any name that starts with a lowercase letter for your own purposes. For example, you can use lowercase as an index variable, as mathematicians like to do.

i

Table[i,{i,1,10}]

## Lists and {Curly Braces}

Lists and {Curly Braces}

{Curly braces} are used to hold lists of expressions separated by commas. Anything can be part of a list.

When you evaluate a list, each of the elements in the list is evaluated and the results are returned in another list.

Evaluate the examples below and you’ll see how this works.

When you evaluate a list, each of the elements in the list is evaluated and the results are returned in another list.

Evaluate the examples below and you’ll see how this works.

{1,2,3,x,y,z}

{Integrate[x^2,x],Integrate[Sin[x],x],Integrate[Tan[x],x]}

Lists really can hold anything, including 2D or 3D graphics.

In[]:=

{Plot[Sin[x],{x,0,2Pi}],Plot[Sin[2x],{x,0,2Pi}],Plot[Sin[3x],{x,0,2Pi}],Plot[Sin[4x],{x,0,2Pi}]}

Evaluate this example to see three interesting knots in a list.

In[]:=

{KnotData["Trefoil"],KnotData["FigureEight"],KnotData["Stevedore"]}

Many types of output in Mathematica are interactive.

Click and drag the individual knots to see them from any angle!

Click and drag the individual knots to see them from any angle!

Many functions allow you to create, operate on, or restructure lists. Here are just a few.

Sort[{3,1,2,5,4}]

Reverse[{1,2,3,4,5}]

Permutations[{1,2,3}]

Lists are the basic building blocks of Mathematica, so the upcoming tutorials will focus on how to create and work with them.

## Range Specifications

Range Specifications

One important use of lists is to hold range specifications (also commonly known as iterators). Each of the commands below contains a set of three elements enclosed in curly brackets of the form {variable, min, max} or {variable, min, max, stepSize}.

Evaluate each of the inputs on this page. Some of them are quite fun!

Evaluate each of the inputs on this page. Some of them are quite fun!

Table[i,{i,1,10}]

Plot[Sin[x],{x,0,2Pi}]

In[]:=

Manipulate[Plot[Sin[nx],{x,0,2Pi}],{n,1,10}]

In Manipulate a step size can be specified. If it is omitted, the variable is allowed to take on a continuous range of values.

This example allows n to take on a continuous range of real numbers.

Manipulate[Expand[(1+x)^n],{n,0,100}]

Here the variable n is restricted to exact integers, allowing the Expand function to do its job.

Manipulate[Expand[(1+x)^n],{n,0,100,1}]

Manipulate has a very wide variety of interactive capabilities, extending well beyond the simple min - max range.

See the (which will open in a separate window).

## Fascinating Mathematica Examples

Fascinating Mathematica Examples

Here are some examples that show that Mathematica is much more than a programming language for mathematics.

Some of these calculations take a while because they are accessing online information.

Some of these calculations take a while because they are accessing online information.

### Amazing mathematics visualizations

Amazing mathematics visualizations

Plotting and interacting with three dimensional functions:

In[]:=

Manipulate[Plot3D[Sin[nxy],{x,0,3},{y,0,3}],{n,1,4}]

The whole Mandelbrot set: (from )

In[]:=

MandelbrotSetPlot[]

A transcendental periodic implicit surface: (from )

In[]:=

ContourPlot3D[Cos[x]Sin[y]+Cos[y]Sin[z]+Cos[z]Sin[x]==0,{x,-2π,2π},{y,-2π,2π},{z,-2π,2π},ContourStyleDirective[FaceForm[Orange,Red],Specularity[White,30]],MeshNone]

Create an interactive Voronoi diagram with movable points. (from )

In[]:=

DynamicModule[{p=RandomReal[{-1,1},{12,2}]},LocatorPane[Dynamic@p,Dynamic@VoronoiMesh[p,{{-1.5,1.5},{-1.5,1.5}},ImageSize500],LocatorAutoCreateTrue]]

### Sociological Analysis

Sociological Analysis

A log-log scatter plot of GDP against population for all countries, with tooltips for country name : (from ref/CountryData)

In[]:=

ListLogLogPlot[Tooltip[{CountryData[#,"Population"],CountryData[#,"GDP"]},CountryData[#,"Name"]]&/@CountryData["Countries"]]

### Geographical Map and Data Integration

Geographical Map and Data Integration

Show national flags of some countries and speak their names when clicked: (from )

In[]:=

GeoGraphics[{GeoStyling[{"Image",CountryData[#,"Flag"]}],EventHandler[Polygon[Entity["Country",#]],{"MouseClicked"Speak[#]}]}&/@{"France","Germany","Italy","Spain"}]

### Image Processing

Image Processing

Adjust Colors in an image (from )

In[]:=

i=

;

In[]:=

Table[ImageAdjust[i,c],{c,{-2,-1/2,1/2,2}}]

### Financial Analysis

Financial Analysis

Plot the stock price for GE since January 1, 2000: (From )

In[]:=

DateListPlot[FinancialData["GE","Jan. 1, 2000"]]

### Social Network Analysis

Social Network Analysis

### Text Analysis

Text Analysis

### Machine Learning

Machine Learning

Train a digit recognizer on 100 examples from the MNIST database of handwritten digits:

Use the classifier to recognize unseen digits:

Analyze probabilities of a misclassified example:

### Identify an image

Identify an image

### Music Generation and Sound Analysis

Music Generation and Sound Analysis

## Getting Help

Getting Help

The Documentation Center is the starting point for all help, including tutorials, guide pages, and function home pages. It is a resource that sets Mathematica apart from other programming languages and is always available from the top of the Help menu.

If you already know or can guess the function you need, and just want to be reminded of its arguments, the ? operator is a quick way to get information without opening a new window.

In Desktop Mathematica, you can hover over any function name to pull up this information or access its function reference page.

## Helpful clues from Mathematica

Helpful clues from Mathematica

Mathematica automatically colors symbols, brackets, and operators to indicate errors or likely errors. When you type a function name, it starts out blue and turns black when it matches the name of a built-in or user-defined symbol.

A blue symbol is not necessarily an error; it simply means that the symbol does not currently have any value or definition associated with it. For example, before the following line is evaluated, the symbol name on the left-hand side is blue, but after evaluation it turns black because a value has been assigned to it. Try this now by evaluating the input cell.

Unmatched brackets or parentheses are given a reddish purple color that indicates a syntax error.

If you nevertheless evaluate such an input, emphasis is added to the unmatched elements in the form of a yellow background.Clicking the yellow symbol near the cell bracket will print out an error message describing the problem (but only after you have evaluated the input).

When a function requires more arguments than you' ve given it, a red caret indicates where more are needed. Conversely, when a function has been given too many arguments, the excess arguments are colored red.

Incorrect option names are colored red.

Local variables of several types are specially colored : in each case below, the variable x is colored (or italicized) because during evaluation it will be given a local value that overrides any global value that may be assigned to it.

## Upward and Onward

Upward and Onward

Where to go from here? Explore! I suggest the following

◼

Explore the Documentation Center. (Click on Help > Documentation Center)

This is the best place to:

This is the best place to:

◼

Learn how to use a function in Mathematica.

◼

Get ready-to-go examples to practice with and build on.

◼

Explore Mathematica's capabilities.

◼

Especially explore the documentation on: Manipulate and Plot.

◼

Go from command to command using the “See Also” links at the bottom of an entry.

◼

Visit the Demonstrations Project online. (http://www.demonstrations.wolfram.com/)

◼

See examples of Mathematica in action in many fields of science and mathematics.

◼

Visit Wolfram Alpha to get started, and then download as "Live Mathematica" (bottom of output) to modify and edit in Mathematica.