A Tour of Mathematica

Mathematica as a Calculator

You can use Mathematica just like a calculator: you type in questions, and Mathematica prints back answers.

3 + 5

57.1^100

Inverse[{{1, 2}, {3, 4}}]

Mathematica can handle formulas as well as numbers.

Integrate[Sqrt[x] Sqrt[1 + x], x]

Solve[x^2 + x == a, x]

Mathematica can also create two and three-dimensional graphics.

Plot[Sin[x] + Sin[1.6  x], {x, 0, 40}]

Plot3D[Sin[x y], {x, 0, 4}, {y, 0, 4}]

Power Computing with Mathematica

Even though you can use it as easily as a calculator, Mathematica gives you access to immense computational power.

ListPlot[Abs[Eigenvalues[m]]]

100!

N[Pi, 100]

Mathematica can work with formulas of any length—solving problems that would have taken years by hand.

Factor[x^99 + y^99]

Simplify[%]

Mathematica has achieved world records—for both size and speed—in many kinds of computations.

PartitionsP[10^9] // Short

Accessing Algorithms in Mathematica

Whenever you use Mathematica you are accessing the world’s largest collection of computational algorithms.

FindRoot[Cos[x] == x + Log[x], {x, 1}]

NIntegrate[Log[x + Sin[x]], {x, 0, 2}]

NSolve[x^5 - 6  x^3 + 8  x + 1 == 0, x]

NMinimize[{Cos[x y] + x, x^2 + y^2 ≤ 10}, {x, 
        y}]

FactorInteger[10^54 - 3]

m = Table[2^i + x^j, {i, 3}, {j, 4}]

MatrixForm[m]

NullSpace[m]

Mathematica can solve differential equations both symbolically and numerically.

NDSolve[{x''[t] + x[t]^3 == Sin[t], x[0] == x'[0] == 0}, 
      x, {t, 0, 50}]

ParametricPlot[Evaluate[{x[t], x'[t]} /. %], {t, 0, 50}]

All of Mathematica’s numerical algorithms are set up to work to whatever accuracy or precision you specify.

Mathematical Knowledge in Mathematica

Mathematica incorporates the knowledge from the world’s mathematical handbooks—and uses its own revolutionary algorithms to go much further.

Mathematica knows about all the hundreds of special functions in pure and applied mathematics.

LegendreQ[3, x]

N[MathieuC[1 + I, 2  I, 3], 50]

Mathematica is now able to do vastly more integrals than were ever before possible for either humans or computers.

Integrate[Sqrt[x] ArcTan[x], x]

Integrate[Log[x] Exp[-x^3], {x, 0, Infinity}]

Sum[1/(k + 1)^6, {k, 0, n}]

DSolve[y''[x] + y'[x] + x y[x] == 0, y[x], x]

Prime[10^9]

FullSimplify[Product[Gamma[2  n /5], {n, 1, 5}]]

Reduce[Exists[x, x^2 + a x + b == 0], {a, b}, Reals]

Log[2] < Zeta[3] < Sqrt[2]

Simplify[Sin[x + 2  π n], n ∈ Integers]

Building Up Computations

Being able to work with formulas lets you easily integrate all the parts of a computation.

Eigenvalues[{{3, 1}, {2, 6}}]

v  =  Eigenvalues[{{3,  1},  {2,  c}}]

Mathematica’s functions are carefully designed so that output from one can easily be used as input to others.

Plot[Evaluate[v], {c, -10, 10}]

Solve[First[v] == 0, c]

Integrate[First[v], c]

Series[%, {c, 0, 4}]

FindRoot[%% == 1 + c^2, {c, 1}]

Being able to work with formulas is also important in summarizing data.

Table[Prime[i], {i, 20}]

Fit[%, {Log[x], x, (x^2)}, x]

Sum[%, {x, 1, 20}]

Sum[Prime[i], {i, 1, 20}]

Handling Data

Mathematica lets you import data in any format, then manipulate it using powerful and flexible functions.

ListDensityPlot[data, Mesh -> False, 
      FrameTicks -> None]

ListDensityPlot[MapIndexed[RotateRight, data], Mesh -> False, 
      FrameTicks -> None]

ListDensityPlot[ListConvolve[{{3, -1}, {-3, 1}}, data], 
      Mesh -> False, FrameTicks -> None]

ListContourPlot[data, ContourShading -> False, Contours -> 6, 
      FrameTicks -> None]

ListPlot[Sort[Flatten[data]]]

ListPlot3D[data, ColorFunction -> GrayLevel, Mesh -> False, 
      ViewPoint -> {0.2, -2, 5}, Ticks -> None]

Mathematica can work with data of any kind — not just numbers.

Select[
      data, (# == StringReverse[#]  &&  
            StringLength[#] > 4) &]

ListPlot[Table[Count[lengths, i], {i, Max[lengths]}]]

Mathematica also has full support for sparse arrays.

Visualization with Mathematica

Mathematica makes it easy to create stunning visual images.

ParametricPlot3D[{u Cos[u] (4 + Cos[v + u]), 
        u Sin[u] (4 + Cos[v + u]), u Sin[v + u]}, {u, 0, 4 Pi}, {v, 
        0, 2 Pi}, PlotPoints -> {60, 12}]

Show[%, PlotRange -> {-10, 0}, BoxRatios -> {1, 1,  .5}, 
      FaceGrids -> {{0, 0, -1}, {0, -1, 0}, {1, 0, 0}}, 
      ViewPoint -> {-1, 3, 2}, Ticks -> None, 
      AxesLabel -> {(Subscript[α, 1]), (Subscript[β, 1]), (Subscript[γ, 1])}]

Mathematica can also generate sound.

Play[Sin[1000/t], {t, 0, 2}]

Mathematica includes primitives from which you can build up 2D and 3D graphics of any complexity.

Take[%, 5]

Show[Graphics[g, Frame -> True]]

Take[%, 5]

Show[Graphics3D[g]]

Mathematica lets you produce animated movies as well as static graphics.

Table[
        Plot3D[Sin[2 x] Sin[2 y] Cos[t], {x, 0, Pi}, {y, 0, Pi}, 
          PlotRange -> {-1, 1}, BoxRatios -> {1, 1, 1}, 
          Ticks -> None], {t, 0, Pi, Pi/24}];

Do[
        ParametricPlot3D[{Cos[i (π/50)] Cos[τ] + 
              Sin[i (π/50)] Sin[σ], Sin[τ], 
            Cos[σ]}, {σ, 0, 2 π}, {τ, 0, 2 π}, 
          Axes -> None, Boxed -> False, PlotPoints -> 20, 
          PlotRange -> {{-1.5, 1.5}, {-1.1, 1.1}, {-1.1, 
                1.1}}], {i, 0, 25}];

Mathematica has made possible many new kinds of scientific, technical and artistic images.

Mathematica Notebooks

Every Mathematica notebook is a complete interactive document combining text, tables, graphics, calculations, and other elements.

Your notebooks are automatically organized in a hierarchy of cells.

You can close groups of cells so you see only their headings.

You can use hyperlinks to jump within a notebook or between notebooks.

You can assign each cell a style from a style sheet.

Your Mathematica notebooks are automatically retargeted for screen or printout—optimizing fonts and layout for each medium.

Mathematica provides hundreds of options that allow you to give notebooks any look you want and to generate full publication-quality documents.

Here is some ordinary text. It can be in any font, face, size, color, and so on. You can have special characters such as 🐺 as well as formulas such as ∫(1/((x^5) - 
                1)) dx embedded in text.

Like other objects in Mathematica, the cells in a notebook, and in fact the whole notebook itself, are all ultimately represented as Mathematica expressions. With the standard notebook front end, you can use the command Show Expression to see the text of the Mathematica expression that corresponds to any particular cell.

Like other objects in Mathematica, the cells in a notebook, and in fact the whole notebook itself, are all ultimately represented as Mathematica expressions. With the standard notebook front end, you can use the command Show Expression to see the text of the Mathematica expression that corresponds to any particular cell.

The Mathematica language can be used to specify all aspects of notebooks.

This is a typical cell.

Mathematica notebooks can be built up using explicit commands as well as interactively.

Heading 1

Heading 2

Heading 3

Palettes and Buttons

Palettes and buttons provide a simple but fully customizable point-and-click interface to Mathematica.

Mathematica comes with a collection of ready-to-use standard palettes.

Palettes work like extensions to your keyboard.

It is easy to create your own custom palettes.

You can make custom palettes to execute any function or manipulate any expression.

Mathematical Notation

Mathematica notebooks fully support standard mathematical notation—for both output and input.

Mathematica combines the compactness of mathematical notation with the precision of a computer language.

Integrate[Log[1 + x]/Sqrt[x], x]

∫Log[1 + ξ]/(Sqrt[ξ]) \[DifferentialD]ξ

TraditionalForm[%]

(∑_(μ = 0)^∞)(( (φ^μ) Exp[((π μ)/4)])/(((μ!)^2) ((μ^2) + κ) ((μ^2) - λ))) // TraditionalForm

\(Table[𝒢⋄\(α\_i⊕β\_i\)\&_⟹Ϡ\+i\%\(6 - i\), {i, 6}]\)

Mathematica and Your Computing Environment

Mathematica runs compatibly across all major computer systems, and lets you exchange data in many standard formats.

Mathematica notebooks allow importing and exporting of many formats.

Notebook files contain only plain text and are completely portable.

Mathematica uses the Unicode standard to ensure portability of international character sets.

Install["sampler.exe"]

Table[getdata[i], {i, 3}]

ListPlot[Sort[Log[10, 1 + sizes]]]

The Unifying Idea of Mathematica

Mathematica is built on the powerful unifying idea that everything can be represented as a symbolic expression.

All symbolic expressions are built up from combinations of the basic form: head[(Subscript[arg, 1]), (Subscript[arg, 2]), …]

The uniformity of symbolic expressions makes it easy to add to Mathematica any construct you want.

All operations in Mathematica are ultimately transformations of symbolic expressions. Mathematica has a uniquely powerful pattern matcher for applying transformation rules.

{a, b, c, d} /. b -> 1 + x

{a + b, c + d, a + c} /. x_ + y_ -> (x^2) + (y^2)

{a + b, c + d, a + c} /. a + x_ -> (x^3)

Mathematica uses patterns to generalize the notion of functions.

f[6] + f[a + b] + f[0]

An important feature of using patterns is that they allow “functions” to take arguments in any structure.

g[{4, a b}]

area[Circle[{2, 3}, u]]

Mathematica as a Programming Language

Mathematica is an unprecedentedly flexible and intuitive programming language.

Mathematica incorporates a range of programming paradigms—so you can write every program in its most natural way.

Procedural programming

z = a;
Do[Print[z *= z + i], {i, 3}]

List-based programming

1 + {a, b, c}^2

Table[i^j, {i, 4}, {j, i}]

Flatten[%]

Partition[%, 2]

Functional programming

NestList[f, x, 4]

NestList[(((1 + #))^2)  &, x, 3]

Rule-based programming

p[a + b + c]

s[{1, 2, 3, 4, 5, 6}, 4]

Object-oriented programming

h[a] + h[b] + f[h[r]] + h[h[x]]

String-based programming

\(StringReplace["aababbaabaabababa", {"aa" -> "AAA", "ba" -> "V"}]\)

Mixed programming paradigms

Position[{1, 2, 3, 4, 5}/2, _Integer]

MapIndexed[Power, {a, b, c, d}]

FixedPointList[If[EvenQ[#], #/2, #] &, 10^5]

ReplaceList[{a, b, c, d, e}, {x__, y__} -> {{x}, {y}}]

A dozen definitions of the factorial function.

Writing Programs in Mathematica

Mathematica’s high-level programming constructs let you build sophisticated programs more quickly than ever before.

Single-line Mathematica programs can perform complex operations.

ListPlot[RandomWalk[200], PlotJoined -> True]

Show[Graphics3D[Line[RandomWalk[1000, 3]]]]

The richness of Mathematica’s programming language makes it easy to implement sophisticated algorithms.

Show[
      CAGraphics[ 
        CAEvolveList[ElementaryRule[30], CenterList[101],  
          50]] ]

Mathematica has a compiler for optimizing programs that work with lists and numbers.

\(Impedance[
        SeriesElement[
          Table[ParallelElement[
              Table[SeriesElement[{Resistor[R\_n]}], {n}]], 
			{n, 1, 
              4}]], ω]\  // Simplify\)

Mathematica programs provide unprecedentedly clear ways to express algorithms.

{g[20], g[20], N[GoldenRatio, 20]}

Mathematica programs allow a unique combination of mathematical and computational notation.

{𝔓[1000], PrimePi[1000]}

Mathematica programs can mix numerical, symbolic, and graphics operations. This short program solves a sophisticated quantum model.

\(Show[Graphics[
		SpectrumData\  /@ \ FareySequence[20]]]\)

Building Systems with Mathematica

Mathematica has everything you need to create complete systems for technical and non-technical applications.

Combinatorica and WorldPlot are two examples of standard add-on packages that come with full versions of Mathematica.

ShowGraph[
      LineGraph[LineGraph[CirculantGraph[5, Range[1, 3]]]]]

WorldPlot is another standard add-on package that comes with Mathematica.

WorldPlot[World, 
      WorldProjection -> 
        N[{#2 (((Abs[Sin[# (Degree/60)]] + 1))/2), #} &], 
      WorldBackground -> Hue[ .5]]

Optica is a large Mathematica package for doing optical engineering.

\(\(\(DrawSystem[{
	ConeOfRays[10, NumberOfRays -> 10], 
	
        Move[PlanoConvexLens[100, 50, 10], {100, 0, 0}], 
	
        Move[PlanoConvexCylindricalLens[100, \ {50, \ 50}, 10], \ {130, 0, 
            0}], 
	Move[
          BeamSplitter[{50, 50}, {50, 50}, 10], \ {180, 0, 45}], 
	
        Boundary[{\(-100\), \(-100\), \(-100\)}, {250, 100, 200}]}, 
      PlotType -> ShadowProject]; \)\(
\)\)\)

Mathematica has made possible a new generation of notebook-based educational courseware.

You can use palettes and buttons to build custom user interfaces.

Technical Trader is a Mathematica system for financial analysis.

({{ADSK, Autodesk,  Inc.}, {BORL, Borland  International}, {INGR, Intergraph  Corp. }, {INTU, Intuit  }, {MSFT, Microsoft }, {NOVL, Novell,  Inc.}, {ORCL, Oracle System  Corp.    }, {SY, Sybase }})

Historical Daily Data for Microsoft (MSFT)

High-Low-Open-Close

Summary Statistics

You can create complete applications and user interfaces directly in Mathematica.

Mathematica as a Software Component

Mathematica’s symbolic architecture and uniform linking mechanism make it uniquely powerful as a component in many kinds of software systems.

You can easily integrate external programs into Mathematica.

Needs["DatabaseAccess`"]
dbselect  =  OpenDataSource["dbselect"]

DataSourceEvaluate[dbselect,  SQLSelect[SQLTable["publishers"]],  
        ShowColumnHeadings  ->  True] // TableForm

The Mathematica J/Link system gives you immediate access to any Java library.

traceTask  =  
        JavaNew["com.wolfram.net.util.TraceRoute"];
\(\(traceTask\ @\ 
        setHost[\ 
JavaNew["java.net.URL", "http://www.wolfram.com/"]];\)\)
traceTask @ execute[];
{"HopCount"  ->  
        traceTask @ getHopCount[],  "HopTimes" ->  
        traceTask@ getHopTimes[]}

MathLink provides a general way for programs to communicate with Mathematica.

MathLink allows multiple Mathematica kernels to communicate.

link = LinkCreate["8000"]

Link = LinkConnect["8000"]

LinkRead[link]

LinkRead[link]

RemoteEvaluate[ $System ]

webMathematica provides a complete solution for building active websites.

MathLink lets you connect to other applications and set up alternative interfaces to Mathematica.

<%@ page language="java" %>
<%@ taglib uri="/webMathematica-taglib" prefix="msp" %>
<!-- webMathematica source code (c) 1999-2003, 
     Wolfram Research, Inc. All rights reserved. -->
<html>
<head>
  <title>Plot</title>
</head>
<body bgcolor="#ffffff" >
  <h1>Plot</h1>
  <form action="Plot.jsp" method="post">
	<msp:allocateKernel>
	Enter a function: 
	<input type="text" name="fun" size="24" value = 
	  "<msp:evaluate>MSPValue[ $$fun,  "Sin[x]^2"]</msp:evaluate>" />
	<br><br>
	Enter a number: 
	<input type="text" name="x1"  size="24" value = 
	  "<msp:evaluate>MSPValue[ $$x1,  "10"]</msp:evaluate>" /> 
	<br><br>
	<msp:evaluate>
	  MSPBlock[ {$$fun, $$x1},
	    MSPShow[ Plot[$$fun, {x,0,$$x1}]]]
	</msp:evaluate>
	<hr>
	</msp:allocateKernel>
	<input type="submit" name="btnSubmit" value="Evaluate"> 
  </form>
  <p><i>
  This example shows how to do plotting with webMathematica.
  </i></p>
</body>
</html>

Mathematica’s symbolic architecture allows direct integration with XML and XML-aware applications.

ExportString[x + 1, "XML"]

atoms  =  
      Cases[mol,  
        XMLElement[_, {_ -> "elementType"}, {type_}] :>  
          type , {0, ∞}]

Map[{#, Count[atoms,  #]} &,   Union[atoms]]