Mathematica Workshop
Mathematica Workshop
What is Mathematica?
Alternatives
- Python, Matlab, etc.
Uses of Mathematica
Today’s Workshop
- Graphing and Plotting
1. Basics of Mathematica
2. Variables and Functions
3. Conditions and Loops
- Creating and Implementing Algorithms 4. Lists and other data structures in
Mathematica
5. Advanced Plotting
- Computation 6. Useful Calculus
7. Exercises and Experimentation
- Communicating ideas
+, -, *, /
Global Variables:
- Value is assigned permanently and will reference that value across other cells
- Will appear in black text
x =. converts back to
local variable
The /. operator
The /. operator can be used to assign a variable to a value for a particular cell
Arrow = ->
Plotting - 2D or 3D support
Conditionals
Unlike in other programming languages, in Mathematica conditionals are
expressed as functions
If function:
- Takes two or three arguments
- Structure: If[Condition, True, False]
- Can be used in functions
- Double = used for comparisons
Logic Operators
AND: &&
OR: ||
NOT: !
Used in logical statements to
specify additional conditions
Which Statement
Also a function
- Works like If but better when
there are multiple cases to
consider
- Used for piecewise functions
Switch Statement
Like an If statement but more
useful for calculations as it will
return a value you specify
- Can be used to plot interesting
functions
- Not limited to binary outputs
Loops
Many types of loops in Mathematica:
- For Loop
- Do Loop
- While Loop
- Nest
Region Plotting
- Much easier to display regions
- 2D or 3D support
Parametric Plotting
- Great for parametric equations
- Animate to add slider
More advanced plotting
3D plots
- Some new parameters you can add
- MeshStyle, ColorFunction, PlotLegends
More advanced plotting
RegionFunction
- Specifies a region (inequality) to leave out of the graph
More advanced plotting
Interpolation
- Interpolation Order - automatically
interpolates data
- Creates a smooth curve
- Can Animate Point plots!
More advanced plotting
Exporting Plots
- You can export plots in many
different file formats
- Animated Plots can be exported as a
video file!
Calculus and Analysis
- Differentiation
- D function
- Prime Notation
- Differential operators in Palette
- Integration
- Integrate Function
- Operator in Pallette
- Numerical Integration
Calculus and Analysis
- Differentiation Equations
- Prime notation
- Uses Comparison ==
- List for initial conditions
- Plot multiple initial conditions!
Exercises
1. Using a conditional, create a function that will display “a divides x” if x (mod a) = 0, and “a does not
divide x” otherwise (useful functions: Mod)
2. Using a loop, create a list that displays the first 30 Fibonacci numbers. Create a function that tests
whether an integer is a Fibonacci number (useful functions: Append, MemberQ)
3. Write a program that takes two vectors in 3D space as input and plots the plane containing those
two vectors as output. Also plot a line in this plane (useful functions: Cross, Graphics3D)
4. Write a function that computes and plots sample mean distribution, using random integers from 1 to
10.
5. Create a 3D graph of a function of your choice over a certain region. Also plot a tangent vector to
the function at a particular point