Introductory Lecture

Overview : CASes versus other Scientific Computing Environments, Mathematica

CASes, or computer algebra systems, are computer programs which facilitate symbolic computations-- they are' algebra systems' because almost all the algorithms involved (even for ODE and PDE solution and integration (Risch algorithm!)) use purely algebraic manipulations.There are a variety of free CASes which are used to varying extents : YACAS (C - based), JACAL (Scheme - based), Axiom (Aldor/Scratchpad - based), Maxima (Lisp - based), etc, but by far the ones used for serious work are proprietary : either Maple or Mathematica.

This portion of the course will serve as an introduction to Mathematica, and hopefully through it, the wider world of CASes.You' ll learn the syntax of Mathematica, but the techniques you learn will be widely applicable to other CASes.For instance, you' ll soon see that no CAS can reliably tell you when A = B; term reduction/canonicalization is a hard problem, so you' ll have to help it out.

Mathematica is unique among the CASes in the degree to which its GUI is an integral part of the system. Because of the tight integration, Mathematica has, in my opinion, the best graphics subsystem among the CASes-- it allows you to treat graphics as first class objects, manipulate graphics interactively, and has a wide variety of plot types. The notebook interface is also a powerful features: (nontrivial) books have been written and published using the Mathematica notebook format. Notebooks can be exported to HTML, various graphic formats, LATEX, pdf, and postscript formats.

By far, the most often used feature of Mathematica is its comprehensive help facility. The Mathematica book, the official documentation and tutorial to the Mathematica system, is included in the help. It is very possible to learn the system from scratch, just from the material provided in the help, and once you know the basics, help becomes useful when you want to look up the syntax of commands, see examples of their usage, or search for new commands.

Stephen Wolfram, the creator of Mathematica, and a Caltech alum (as is Cleve Moler)

Mathematica versus Matlab

Mathematica is a CAS, so its emphasis is on symbolic, rather than numerical computation. On the other hand, Mathematica is not limited to machine precision, so if you need arbitrary precision numerical computations (e.g. computational algebraic geometry), it is an option. Wolfram claims that the new generation of Mathematica has  ' gigaNumerics' which allows it to outperform specialist numerical systems, but I' ve yet to see the fruits of this feature.
   
   Another instance where one might desire to use Mathematica over Matlab even for numerical applications is for throw - away coding. Because Mathematica supports several classes of programming : rule - based, procedural, and functional, and has a more flexible interface than Matlab' s relatively restrictive m - file structure, it is often quicker to write and test short routines in Mathematica. An amazing array of computations can be performed in one line of Mathematica code.
   
   Mathematica is excellent for daily use as a supercharged TI-89: finding solutions to ODEs, calculating integrals, etc. In principle, you could use Matlab to do many of these things, through its Maple-powered symbolic toolbox, but in practice that's more work than just using Mathematica. 
    
    In the final analysis, Mathematica can theoretically do everything Matlab can do, and Matlab can theoretically do a lot of the same symbolic computations Mathematica can, through its symbolic toolbox, but Mathematica has a much more amenable interface and syntax for symbolic computations, and Matlab is faster at numerical computations (assuming that the gigaNumerics claim is, as it seems to me, a marketing gimmick)

Using Mathematica as a Calculator

Standard Calculator

1+2

20 30

Out[3] +Out[2]
In[2]

N[π, 450]

Mod[25,3]

2π (3)^2 //N

Cos[30 (π/180)] Sin[40 (π/180)]

(1/2) (Sqrt[3]) Sin[((2 π)/9)]//N

Graphing Calculator

Plot[Sin[x]^2, {x,0,2π}]

Plot[((Sin[x])^2)((Cos[x])^2), {x,0,2π}, Frame->True, Filling->Axis]

Plot3D[Exp[-(x^2+y^2)]Cos[x^2+y^2], {x,-4,4}, {y,-2,2}]
Plot3D[Exp[-(x^2+y^2)]Cos[x^2+y^2], {x,-4,4}, {y,-2,2}, PlotRange->All]

ListPlot[NestList[Cos[#] &, 2, 60], Filling->Axis, PlotRange->All]
Manipulate[ListPlot[NestList[Cos[#] &, start, 60], Filling->Axis, PlotRange->All], {start,0, 2π}]

Solve[a (x^2) + b y == c, {x}]

Solve[Cos[Sin[x]] == α, {x}]

Calculus, ODEs

Integrate[Cos[x] (E^(-x)),{x,0,∞}]

Integrate[Exp[-x^2], x]

Sum[(1/(n^2)),{n,1,∞}]

Product[ (x^(2-n)) ,{n,1,∞}]

FourierTransform[UnitStep[t^2] (t^2) ArcCos[t], t, ω]

Integrate[(x^x),x]

DSolve[ {r''[x] + r'[x]r[x]==6, r[0]==1, r'[0]==1}, r[x], x]

h[z_] := First[r[x] /. Out[90]] /. x->z;
D[h[z], {z,2}] + D[h[z], z] h[z] // FullSimplify
h[0] // FullSimplify
D[h[z],z] /. z->0 //FullSimplify
Plot[h[z], {z,0,200}]

Notes on Basic Syntax

Everything in Mathematica is represented as an expression : something of the form head[arg1, arg2, …]

Cos[(t/4)] Product[Integrate[x^k, {x,0,ℵ}], {k,1,10}]

Short[FullForm@Plot[Sin[x], {x,0,2π}] ,10]

A particularly ubiquitous form of expression is the list : {a, b, c, …}
Some functions operate over lists; these have the Listable attribute
Vectors are lists and Matrices are lists of lists

Cos[{a,b,c}]

??Cos

v = RandomReal[{0,1}, 45]
A = RandomReal[{0, 10}, {14,45}];
A // MatrixForm
r = A . v;
Length[r]
Dimensions[A]

Because it can be painful to nest expressions, Mathematica provides some shortcuts:
f[x], f@x, x //f
f[x,y], x~f~y

Infix[head[a,b,c,d]]
Postfix[f[x]]
Prefix[f[x+y]]

N@Cos@45
Cos[45] //N

Mathematica' s Notebook Interface

Demonstrate the features of Mathematica' s interface and notebooks : cells (styles and formats) , referring to past inputs, palettes and evaluation controls, help (both the browser and the inline help), interaction of notebooks, two-dimensional input, clearing variables and quitting kernel, aborting calculations

Next Time

Lists and List manipulations
Function definition
Rules and Patterns