Mathematica Tutorial

PAC200 - open computer lab with Mathematica & available tutors
 
Mathematica
One of the computational software programs used in many scientific, engineering, mathematical and computing fields.




Invented by Stephen Wolfram and is developed by Wolfram Research of Champaign, Illinois.
  • Mathematica 1.0 (June 23, 1988)
  • Mathematica 9.0.1 (January 30, 2013)
    .
Stephen Wolfram -
Married with 4 kids, PhD from Cal Tech physics department, was a child of Jewish refugees. His work in physics led him to create a computer program that solved, first algebra problems, then more complex systems.  Eventually, he left academia to create his own company (Wolfram).

He is the author of "A New Kind of Science", a book where he theorizes that the universe is digital in nature, and runs on fundamental laws which can be described as simple programs. 

He has now expanded his program to answer, not just math problems, but all kinds of questions.  His work is used by Bling, Google, Siri, and Yelp's search engines.

He has many youtubes, including the TED talk:

 Stephen Wolfram: Computing a theory of everything
https://www.youtube.com/watch?v=60P7717-XOQ
Features of Mathematica include:
*Elementary mathematical function library
*Matrix and data manipulation tools
*2D and 3D graphing
*Solvers for systems of equations
*Numeric and symbolic tools for discrete and continuous calculus
*Multivariate statistics libraries

Opening Mathematica up:
 
Start → All PRoegrams →Mathematica
If others have recently used it-
 
 
or you might have to dig for it -
 
Create a new notebook:
 
 
Open up your math assist palette
 
 
Have a look around your math pallet, this will be used to help type in equations - you can create things like fractions, exponents, square roots, use different symbols, etc.
 
 
 
Typing inside the notebook:
 

Vertical cursor – Click on screen while curser is vertical to type something into an existing section
Horizontal cursor – Click on screen and hit <enter> while curser is horizontal to create a new cell

enter key – inserts new lines into cell
Shift+enter  or <enter> on the numerica keypad computes results 
               
Try something simple, type in "2+2" then shift + enter:
 
 
 
Open up the Mathematica documentation center:
 
 
 
 
Inside you will find 10,000 pages of info on all the functions with examples and tutorials on how to use them


Check out:
      *Visualizations and Graphics,
      *Mathematics and Algorithms,
      *Data Manipulation

Just type something in, cut and paste the examples out of the help - modify examples to do what you need to do.

Example: type in solve, hit enter


Copy and paste the input into your notebook:

hit shift + enter:

The tricky part about Mathematica is just learning the nomenclature
It uses square brackets [] to surround functions, curly brackets to separate arguments {}, two equal signs ==, capital letters for functions Solve[... etc.  Just copy and paste out of the examples in the documentations center until you get used to how to type things in.


Graphing:





help - Virtual book
Highlight function - help (or F1) - find selected function
type "?" followed by what you want help with:
?Plot - bring up Plot examples

?Plot* - everything that starts with plot

Plo... - edit, complete selection (ctrl - K)

Edit - make template - (Ctrl + Shift + K) - fill in basic structure of a function.



Fill in the values you need.






Pallets: Use to input formulas,
Start with the "Basic Math" pallet.



Function[square bracket, arguments separated with commas]

Sin[2.3]
Plus[2,2] = 2+2


 List and Matrix operations:
Mean[{30, 34, 29, 15}]

Inverse of 3 by 3 matrix:
Inverse[{{a,b,c}, {d,e,f}, {g,h,i}}]
Inverse[{{1st row}, {2nd row}, {3rd row}}]

 



Determinant:
Det[{{1, 2, 3, 4}, {5, 6, 7, 8}, {1, 7, 4, 3}, {1, 2, 3, 5}}]




m = {{1, 2, 3, 4}, {5, 6, 7, 8}, {1, 7, 4, 3}, {1, 2, 3, 5}}
m.m.m


Solve:

use "==" - two equal symbols

 
 
 
 

Solve[x^2-5x+6==0, x]  (shift + enter)
{{x-2}, {x-3}}

Solve[x^2+x+1==0, x]//N
//N - gives answer in numerical form
{{x-.5-.86i},{x-.5+.86i}}

Solve[a*x^2 + b*x + c==0, x]
x = quadratic formula

Solve system of equations - use {}
Solve[{3 x + 2 y ==15, 3*x - 3*y == 12}, {x, y}]//N



Numerical solution
(for problems you can't solve with algebra)

FindRoot[Log[x]==Exp[x]-5, {x,3}]
{x,3} 3 = num you start guessing with, it will find the solution closest to 3.

Plot[{Log[x], Exp[x]-5}, {x, 0, 2.5}]
intersection of two lines = solution

note - ln(x) = Log[x]


Solve[Sin[x]==.5, x]
 - gives an infinite # of solutions:

Reduce[Sin[x]==.5,x]
Plot[{Sin[x], .5}, {x, 0, 6*Pi}]




Graphing:

Points:
ListLinePlot[{{1,2}, {3, 4}, {5,3}}]



 


Plot[Sin[x]/x , {x, -9.4, 9.4}]

Plot3D[Sin[x*y], {x, -Sqrt[3*Pi], Sqrt[3*Pi]}, {y, -Sqrt[3*Pi], Sqrt[3*Pi]}]

to rotate graph with mouse – just click on it with mouse
(Shift) + (move mouse) to pan around
(Ctrl) + (mouse) to zoom in and out.


ContourPlot
[Sin[2*x*y], {x, -Sqrt[3*Pi],
Sqrt[3*Pi]}, {y, -Sqrt[3*Pi], Sqrt[3*Pi]}]
 
Plot[Tooltip[{Sin[x], Sin[x]/x}], {x, -8, 8}] 

Move mouse over it to get #’s

Multiple plots on the same axis:
Plot[{Sin[x], Sin[x]/x}, {x, -8, 8}]

plot1=Plot[x^2+3,{x,-5,5}];
plot2=Plot[x+3, {x,-5,5}];
(; suppresses output)
Show[plot1, plot2]


Click on graph, then customize it with menu below it, or see everything you can do to it through:

Options[Plot]

Table[Plot[Sin[x]/x, {x, 0, 2 Pi}, Filling -> Top]]
AxesLabel→{“x”, “y”, “z”}, 
Mesh→None, 
ColorFunction→Function[{x, y, z}, Hue[x x y]], 
ImageSize→600
Plotrange→{{-0.25, 1.25}, {-0.25, 1.25}, 
PlotStyle→{{Dashing[0.5}, Black}, Black}, 
AspectRatio→Automatic, 
Filling→{1→Bottom, 2→Top}, 
FillingStyle→{1→Directive[{Red, Opacity[0.5]}], 2→Directive[{Yellow, Opacity[0.5]}]}]

Frame→True,
Axes→true,
LabelStyle→{FontFamily→”Arial”, FontSize→24},
FrameLabel→{Time (s)”, “Displacement (cm)”},
PlotStyle→{Red, Thickness[0.01]}


Click and drag to make larger or smaller

graphics – drawing tools – draw on arrow, text boxes, etc.



double click on curve to move it around, etc.

ListPlot

Plot a function:

 

Step-by-step + easy input:
Find a spot where the curser is horizontal
type ==  (two equal signs) shift enter
in this mode you don't have to remember the exact nomenclature to type everything in with. 





 

******************************************************************************
Just for fun:

Mathematica One-Liner Competition: What can you create with 140 characters or less?
http://www.youtube.com/watch?v=4MJteuXijAs

notebook of winning entries:http://www.wolfram.com/training/special-event/mathematica-experts-live-one-liner-competition-2012/




http://www.bugman123.com/Fractals/


Certification:
http://www.wolfram.com/training/certification/students/