An Introduction to Mathematica

George E. Hrabovsky

MAST

What We Will Cover

Here is the agenda of this talk.

What Is Mathematica?

What is a Computer Algebra System?

What is the Structure of Mathematica?

What are the core principles of Mathematica?

How Do We Use Mathematica?

The Documentation System

Mathematica as a Scratchpad

Mathematica as a Discovery Tool

Mathematica as a Programming Environment

Mathematica as a Computational Lab

Mathematica as a Word Processor

Mathematica as a Classroom

Where Can I Get Mathematica?

What Now?

Free-form workshop setting to demonstrate how to do things.

What Is Mathematica?

Mathematica is a computational environment allowing for many modes of operation:

You can use its built-in capabilities as a Computer Algebra System (CAS) to do symbolic mathematical work.

You can use its built-in capabilities to perform numerical mathematical work.

You can use it as a scratch pad for mathematical work.

You can use it for data analysis and visualization.

You can use it for image and audio processing.

It is a fully capable programming language allowing you to use and mix programming paradigms at will.

You can use it to create and maintain documents and slide shows.

We will see how many of these capabilities work.

What is a Computer Algebra System (CAS)?

This is a now, mostly, outdated term to describe systems that allow you to perform symbolic mathematical operations on a computer instead of the tradition numerical operations. I consider it outdated because niether of the two principle systems (Mathematica and Maple) are strictly algebra systems, as they both have very capable numerical and general programming capabilities.

    The first CAS I know of was called MathLab and came out in 1964. It brought about what can be considered the first generation of CAS. These are exclusively written in, and require the use of, the programming language LISP.

    Reduce came out in 1968, it is now in the public domain. Reduce is also a first-generation system—it is written in, and requires, LISP. It is freely available form the website: http://www.reduce-algebra.com/ .

    Then Macsyma was developed,in 1969. This had an interesting development path. Macsyma was sold commercially for a while, and is now defunct. MIT had a version of it under the DOE, called Maxima, which entered the public domain. This is now available at the website: http://maxima.sourceforge.net/ .

    Scratchpad was the next first-generation system and it came out in 1974,. This is was a remarkable system that later became Axiom,. Axiom is now terribly out of date, at least in terms of its interface, and is available at the web site: http://axiom.axiom-developer.org/ .

    MuMath, which later became Derive, came into being in 1979, and was the last of the first-generation systems developed in LISP. Derive had an interesting life. Starting out as a reduced-strength CAS for students, it saw life in certain powerful hand-held calculators.

    Maple is a second-generation system written in C and C++ and first arrived in 1983 from Waterloo Software (now owned by Cybernet Systems Group). It is now a fully capable environment for programming and scientific discovery.

    MuPAD came out in 1992 and is available only as a MATLAB add-on. I consider this to be extremely expensive, since you need MATLAB and then MuPAD.

    Mathematica came out in 1988, also written in C/C++, is the most popular of the general CAS. It began around 1981 when Stephen Wolfram wrote the SMP CAS while at CalTech.

What is the Structure of Mathematica?

The Kernel(s)

This is the part that does all of the work. It can be thought of as an internal engine. It interprets all commands, processes all requests, and produces all output. The computational engine is called the Wolfram Language.

The Mathematica Notebook

This is the most common interface with the kernel. You type in the input and the formatted output is displayed. It is a file that allows you to record your sessions and produce high-quality typesetting. All input and output are in the form of cells marked by brackets on the right hand side of the notebook

What are the Core Principles of Using Mathematica?

Everything in Mathematica takes place in a cell. Cells are bounded on the right by the square brackets you see. Cells allow you to perform operations on whatever is within the cell. You can copy, cut, delete, and paste cells. As we go we will see other operations we can perform on cells, too.

    Everything within a Mathematica cell is an expression. It can be a number, a string of text, a paragraph, an equation, a command, a photograph, a piece of music, a program, or a database—all are examples of expressions in Mathematica. There are numerous ways to manipulate expressions, and we will get around to exploring them.

    An expression that accepts input and produces output is called a function. In Mathematica there are two aspects of functions that are important. First, all Mathematica functions begin with an upper-case letter. Second, after the function label, called the Head in Mathematica-ese, are enclosing square brackets [ ], where you place the expression that the function is to act on, called the Argument of the function.

How Do We Use Mathematica?

We can open a cell by placing the cursor at a new line and just start typing.

You can also put the cursor at a new line and click on the tab. In presntation mode the tab does not appear.

You can change the form of a cell by highlighting the bracket, and then choosing the cell type you want. Make sure the formatting toolbar is active.

Now we open a cell. Then we choose the format Input. Then we type an expression. We can tell Mathematica to evaluation by holding down the [SHIFT] key and then typing [ENTER]. On a Mac this sequence is different.

Notice that we now know about text cells, input cells, and output cells.

Mathematica, not suprisingly, understands arithmetic. It can add,

mmaintro_1.png

mmaintro_2.png

it can multiply,,

mmaintro_3.png

mmaintro_4.png

it can raise a number to a power

mmaintro_5.png

mmaintro_6.png

It also has functions for each of these operations.

mmaintro_7.png

mmaintro_8.png

mmaintro_9.png

mmaintro_10.png

mmaintro_11.png

mmaintro_12.png

Mathematica knows about the inverse operations, too.

mmaintro_13.png

mmaintro_14.png

mmaintro_15.png

mmaintro_16.png

mmaintro_17.png

mmaintro_18.png

We can get the numerical approximation of this by adding a function on the end using //, then naming the function, in this case N.

mmaintro_19.png

mmaintro_20.png

mmaintro_21.png

mmaintro_22.png

Assume we have the power

mmaintro_23.png

mmaintro_24.png

There are two inverses, the 6th root and the base 12 logarithm.

mmaintro_25.png

mmaintro_26.png

mmaintro_27.png

mmaintro_28.png

mmaintro_29.png

mmaintro_30.png

We can get a clue about how Mathematica is evaluating a calculation by using the command FullForm[ ]

mmaintro_31.png

mmaintro_32.png

We can get a graphical representation of this using TreeForm[ ]

mmaintro_33.png

mmaintro_34.gif

Note that when you mouse over the squares, at least in Mathematica or the CDF reader (we will discuss this later on).

Mathematica can deal with units of measurement in a primitive way. For example, if we want to determine the distance traveled at some speed,

mmaintro_35.png

mmaintro_36.png

Note that Mathematica handles all simplifications.

Mathematica can deal explicitly with units by using the Quantity[ ] command.

mmaintro_37.png

mmaintro_38.png

This generates a warning, to suppress it we aply the Quiet command.

We can then convert between units using the  UnitConvert[ ] function

mmaintro_39.png

mmaintro_40.png

In Mathematica there are two kinds of assignments. Both types allow you to label an expression.and call that expression whenever you use that label.

An immediate assignment uses the = symbol and it immediately applies the expression to the label.

mmaintro_41.png

mmaintro_42.png

mmaintro_43.png

mmaintro_44.png

A delayed assignment holds the value of the expression as unevaluated until it is requested.

mmaintro_45.png

mmaintro_46.png

mmaintro_47.png

mmaintro_48.png

mmaintro_49.png

mmaintro_50.png

mmaintro_51.png

mmaintro_52.png

mmaintro_53.png

mmaintro_54.png

mmaintro_55.png

The delayed versions executes the command afresh every time you use it.

We can refer to the previouis output using the %% symbol.

mmaintro_56.png

mmaintro_57.png

Note that every output cell has a number associated with it. We can refer to a previous result by using the %number symbol.

mmaintro_58.png

mmaintro_59.png

A more sophisticated, and easier to understand, method of assignment is to label each expression, then refer to it through that assignment.

Mathematica understands algebra. Here we use the Expand[ ] function.

mmaintro_60.png

mmaintro_61.png

We can also Factor[ ]

mmaintro_62.png

mmaintro_63.png

mmaintro_64.png

mmaintro_65.png

mmaintro_66.png

mmaintro_67.png

We can pull out parts of an expression using Coefficient[ ], Exponent[ ], Part[ ], Numerator[ ], and Denominator[ ]

mmaintro_68.png

mmaintro_69.png

mmaintro_70.png

mmaintro_71.png

mmaintro_72.png

mmaintro_73.png

mmaintro_74.png

mmaintro_75.png

mmaintro_76.png

mmaintro_77.png

mmaintro_78.png

mmaintro_79.png

mmaintro_80.png

mmaintro_81.png

We can rearrange formulas by collecting in terms of the powers of a specified variable using Collect[ ]

mmaintro_82.png

mmaintro_83.png

We can gather a sum over a common denominator using Together[ ]

mmaintro_84.png

mmaintro_85.png

We can separate an expression into more terms using Apart[ ]

mmaintro_86.png

mmaintro_87.png

We can use the function Cancel[ ] to remove common factors between a numerator and denominator.

mmaintro_88.png

mmaintro_89.png

It is rare when you have only a single value for a variable. Mathematica allows you to manipulate lists of expressions. You can create them manually using curly brackets.

mmaintro_90.png

mmaintro_91.png

When we want to use a symbol later, we can clear its assignmernt if we decide it is not important.

mmaintro_92.png

For example, we can assign the components of a vector,

mmaintro_93.png

mmaintro_94.png

We can also use Range[ ]

mmaintro_95.png

mmaintro_96.png

mmaintro_97.png

mmaintro_98.png

You can create lists using a table, Table[ ]

mmaintro_99.png

mmaintro_100.png

mmaintro_101.png

1 1 1
2 4 mmaintro_102.png
3 9 mmaintro_103.png
4 16 2
5 25 mmaintro_104.png
6 36 mmaintro_105.png
7 49 mmaintro_106.png
8 64 mmaintro_107.png
9 81 3
10 100 mmaintro_108.png

mmaintro_109.png

1
2 t
mmaintro_110.png

mmaintro_111.png

mmaintro_112.png

Table is a very powerful programming tool. Learn to use it!

We can use Row[ ] to create structured output.

mmaintro_113.png

mmaintro_114.png

mmaintro_115.png

mmaintro_116.png

We can use Column[ ] too,

mmaintro_117.png

Here is
a vertical list
aligned on the left
with a plot
mmaintro_118.gif

If we have a formula, we can use Plot[ ] to represent its curve graphically.

mmaintro_119.png

mmaintro_120.gif

For functions of two variables, we can use Plot3D[ ]

mmaintro_121.png

mmaintro_122.gif

We can also use ContourPlot[ ]

mmaintro_123.png

mmaintro_124.gif

and DensityPlot[ ]

mmaintro_125.png

mmaintro_126.gif

The Documentation System

Of course, it is impossible to cover all of the functions in Mathematica in a comprehensive way. Each version of Mathematica over the last three years have produced more functions than existed in the original version. Get to know the documentation system. You access it through the Help Menu. There are thousands of pages of very useful information.

mmaintro_127.png

mmaintro_128.png

Mathematica as a Scratchpad

The easiest way to use Mathematica is a scratchpad. You use it just like you would a piece of paper. We will do this when we get to the workshop section of this presentation.

Mathematica as a Discovery Tool

If you are messing around, or you don’t know where to start you can always try free-form input. You can choose this from the tab,

Or you can hold down the [CTRL] key and then type =

Notice that the free-form input is transformed into its Wolfram Language equivalent. For example, if we type in, “derivative of sine of x”

mmaintro_129.gif

You can also, assuming you are connected to the Internet, launch a WolframAlpha session.

mmaintro_130.png

Mathematica as a Programming Environment

Mathematica is also a fully-functional programming environment within the notebook front end.

The simplest type of program is to create your own function

mmaintro_132.png

mmaintro_133.png

mmaintro_134.png

Note that we used an underscore in the function name, this is a place holder and tells Mathematica to replace the underscored lable with whatever you type in in the function command.

We can separate the names of local variables from global variables using Module[ ]

mmaintro_135.png

mmaintro_136.png

You can separate local values from global values using the Block[ ] function. For example, you can use Block[ ] to use a variable name used elsewhere, with a global value, and give it different value just for your command.

Mathematica as a Computational Lab

We can build graphical user interfaces on the fly using Manipulate[ ]. Since you can deploy these on web pages, either embedded, or in cdf-type documents (a Wolfram created format), allowing users to use them interactively.

mmaintro_137.png

Mathematica as a Word Processor

You can use Mathematica as an almost-fully functional word processor. It does poorly at multiple columns on a page.

It is a good choice for scientific writing as it allows you to merge text, graphics, and mathematical symbols seamlessly.

If you want to insert formatted mathematics into a line of text, you simply hold down the [CTRL] key and press (. This opens a formula cell. You type in the formula, or choose the symbols from the available palettes. When you are done you again hold down the [CTRL] key and press ).

Mathematica also allows you to produce high quality pdf documents on the fly.

Mathematica as a Classroom

We can perform slide shows in Mathematica. As we have seen, the advantage is that the system is fully interactive.

You can produce cdf style documents that allow users free access to specific commands using a manipulate. Such a document requires only the free CDF player available from Wolfram Research.

You can make an entire notebook into an HTML document for deployment on a web site.

You can embed a manipulate onto a web page, so that people with the CDF Player can manipulate it. Only 32-bit browsers can do so.

Where Can I Get Mathematica?

There are two ways to get Mathematica. You can pay for it from Wolfram Research. Or you can get a Raspberry Pi computer, where it is freely available. There are three types for purchase:

Professional Version, this allows you to do professional work and costs from $2500 to $3500 depending on whatever kind of deal you can get.

Personal Version, this can only be used for hobby purposes (unless you already own a professional version). This costs a bit less than $300. There is no functional difference between the versions.

Student Version, this is only available if you have a valid student ID from a recognized school. It runs about $150.

Created with the Wolfram Language