Chapter 2 Introduction To Mathematica
Chapter 2 Introduction To Mathematica
Software
Chapter 2: Introduction to Mathematica
What is Mathematica?
▶ A powerful computational software system developed by Wolfram
Research.
▶ Capable of symbolic computations, numerical calculations, data
visualization, and more.
▶ Used in mathematics, science, engineering, finance, and education.
▶ Combines a computer algebra system with programming and
visualization capabilities.
▶ Based on the Wolfram Language.
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 3 / 126
Why Use Mathematica?
Key Capabilities
▶ Symbolic algebra
▶ Numerical computation
▶ 2D and 3D graphics
▶ Data analysis and visualization
▶ Programming and algorithm development
▶ Scientific research and education
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 4 / 126
Using Palettes and Entering Expressions
Palettes Overview
▶ Mathematica allows expressions in natural textbook form.
▶ Palettes help insert mathematical symbols.
▶ The Basic Math Assistant palette is commonly used.
▶ Open it from the Palettes menu.
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 5 / 126
How to Start Mathematica
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 6 / 126
Defining Functions in Mathematica
Example Function
√︀
f (x) = x2 + 1
Input
f[x_] := Sqrt[x^2 + 1]
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 7 / 126
Basic Concepts: Arithmetic Operations
Critical Distinction
xy (no space) is a single variable named xy.
x y (with a space) is the product of x and y. The space is essential!
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 8 / 126
Basic Computations
Arithmetic Operations
2 + 3
5 * 4
10/3
2^5
Sqrt[16]
Algebraic Computations
Expand[(x + 2)^3]
Factor[x^2 - 9]
Solve[x^2 - 4 == 0, x]
Simplify[(x^2 - 1)/(x - 1)]
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 9 / 126
Defining Functions in Mathematica
Function Concept
A function in Mathematica:
▶ Is defined using a name and arguments.
▶ Requires a Blank ( ) after each argument name on the left-hand side.
This pattern matches any expression.
▶ Can use either = (Set) or := (SetDelayed) for definition.
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 10 / 126
Defining Functions: Examples
Single-Variable Function
Define f (x) = x 3 − 2x:
f[x_] := x^3 - 2x
f[3] (* This returns 21 *)
Multiple Arguments
g[x_, y_] := x^2 + y^2
g[3, 4] (* This returns 25 *)
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 11 / 126
Set (=) vs SetDelayed (:=)
Comparison Example
f[x_] = D[(x+1) Cos[x], x] (* Derivative computed once at definition *
g[x_] := D[(x+1) Cos[x], x] (* Derivative recomputed for each call *)
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 12 / 126
Constants and Built-in Functions
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 13 / 126
Logical Relations: = vs. ==
Example
x = 5; (* Assigns the value 5 to x *)
x == 5 (* Asks: is x equal to 5? Returns True *)
x == 4 (* Asks: is x equal to 4? Returns False *)
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 14 / 126
Logical Comparison Operator: == (Equal)
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 15 / 126
Logical Operations
These operations combine logical expressions (which are either True or
False).
Practical Example
x = 7;
x > 5 && x < 10 (* Returns True because both conditions are True *)
x < 5 || x > 10 (* Returns False because neither condition is True *)
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 16 / 126
Summary: Basic Concepts
Key Takeaways
▶ Arithmetic: Use +, -, *, /, ^. Remember space for multiplication.
▶ Functions: Define with f[x ] := .... The underscore ( ) is crucial.
▶ Constants: Built-in constants start with capitals: Pi, E, I, Degree.
▶ Logic: = for assignment, == for comparison.
▶ Clean Up: Use Clear[var1, var2] to avoid old definitions
interfering.
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 17 / 126
Multiplication and Multiple Commands
Three Ways to Multiply
▶ Using a Space: 217 5713 (space is interpreted as multiplication)
▶ Using an Asterisk: 321 * 5.479
▶ Juxtaposition: 2x (when no ambiguity between variable and number)
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 20 / 126
Common Syntax Errors
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 21 / 126
Exact vs. Numerical Computation
Symbolic by Default
Mathematica computes symbolically (exactly) unless told otherwise:
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 22 / 126
Built-in Functions and Naming
Capitalization Rule
All built-in objects follow a strict convention:
▶ They begin with a capital letter (e.g., Sin, Plot).
▶ Multi-word names capitalize each word (e.g., FindRoot,
AspectRatio).
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 23 / 126
Elementary Functions
Sin[Pi/12], ArcTan[1], ArcCos[1/2], Log[E]
Important:
▶ Inverse trig functions use ”Arc-” prefix (ArcSin, not Sin^-1).
▶ Natural logarithm is Log, not Ln. Log[10, x] gives log10 (x).
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 24 / 126
Algebraic Manipulation: Expand and Factor
Computer Algebra System (CAS)
Mathematica’s core strength is symbolic manipulation:
▶ Works with expressions symbolically, not just numbers.
▶ Performs exact algebraic computation.
▶ Simplifies, expands, and factors expressions.
Expand Factor
Transforms product into Transforms polynomial into
polynomial (sum of terms). product of factors.
Together Apart
Combines multiple fractions into Decomposes single fraction into
single fraction with common sum of simpler partial fractions.
denominator.
Apart[1/(x(x+1))]
Together[1/x + 1/(x+1)]
Result:
Result: 1 1
−
2x + 1 x x +1
x(x + 1)
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 26 / 126
Simplification: Simplify and FullSimplify
Simplify
Attempts to find simplest algebraic form:
FullSimplify
More powerful (but potentially slower) simplifier:
FullSimplify[Sin[x]^2 + Cos[x]^2]
Result: 1. Applies broader set of rules, including trig and special function
identities.
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 27 / 126
Exact vs Approximate in Algebra
Exact Arithmetic is Default
Mathematica keeps everything symbolic and exact unless asked for
numbers:
1/3 + 1/6 (*
Returns 1/2 , exact
fraction *)
Expand [( x +1) ^5] (*
Returns exact polynomial
*)
Numerical Approximation
Use N[ ] or decimal point to force numeric result:
N [1/3 + 1/6] (*
Returns 0.5 *)
(3+1) ^5 (*
Returns 1024 , because
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 28 / 126
Common Algebraic Mistakes
Frequent Errors
▶ Mixing decimals with exact: Using 0.5 instead of 1/2 can prevent
symbolic simplifications.
▶ Forgetting Simplify: Mathematica doesn’t auto-simplify; you must
call Simplify.
▶ Using Expand when Factor intended (and vice versa).
No Automatic Simplification
Mathematica does not automatically simplify all expressions:
x (3 - x ) - 5 x ^2 + ( x - 1) (2 x + 3)
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 30 / 126
Summary: Basic Calculations
Key Takeaways
▶ Syntax: () for grouping, [] for functions, {} for lists.
▶ Multiple Commands: Separate with ; to suppress output.
▶ Exact vs. Numeric: Mathematica is exact by default. Use N[] for
decimals.
▶ Built-in Functions: Always start with capital letter (e.g., Log, not
ln).
▶ Algebraic Ops: Expand, Factor, Together, Apart, Simplify are
core tools.
▶ Explicit Simplification: Mathematica does not simplify
automatically; you must call Simplify.
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 31 / 126
Lists: Introduction
Definition (List)
A list is a collection of elements treated as a single object. In
Mathematica, lists are written using curly braces { }.
Creating Lists
▶ Direct enumeration: {1, 4, 5, 6, 9} (equivalent to
List[1,4,5,6,9]).
▶ Using Range for arithmetic sequences:
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 32 / 126
▶ Range[10] generates
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
▶ Range[10,15] generates
▶ Range[10,15,1/2] generates
{10, 10.5, 11, 11.5, 12, 12.5, 13, 13.5, 14, 14.5, 15}
Key Point
Lists are the fundamental data structure in Mathematica, used for vectors,
matrices, datasets, and plotting coordinates.
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 33 / 126
Lists: Accessing Elements
Creating a List
L = {10, 20, 30, 40}
Accessing Elements
Use double square brackets [[ ]] with 1-based indexing:
L[[1]] (* 10 *)
L[[3]] (* 30 *)
L[[-1]] (* 40 *)
Important
▶ Indexing starts at 1, not 0.
▶ Use [[ ]] for indexing.
▶ L[1] is incorrect syntax in Mathematica.
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 34 / 126
Operations on Lists: Vectorization
Vectorized Operations
Mathematica automatically applies many operations to every element in a
list.
Examples
L = {10, 11, 12, 13, 14, 15};
L^2
Sqrt[L]
2*L
Range[5]^2
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 35 / 126
The Range Function
Purpose
Range generates arithmetic sequences.
Examples
Range[5]
Range[2,10]
Range[0,1,0.2]
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 36 / 126
The Table Function
Purpose
Table evaluates an expression repeatedly for an iterator.
Examples
Squares:
Table[i^2, {i,1,5}]
Equivalent:
Range[5]^2
Fractional step:
Table[Sqrt[x], {x,1,3,0.5}]
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 37 / 126
Table: Creating Matrices
Example
Table[i + j, {i,1,3}, {j,1,3}]
Result: ⎛ ⎞
2 3 4
⎝3 4 5 ⎠
4 5 6
Mathematica output:
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 38 / 126
The NestList Function
Purpose
NestList repeatedly applies a function and returns all intermediate values.
Example
NestList[#^2 &, 2, 4]
Returns:
{2, 4, 16, 256, 65536}
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 39 / 126
Basic List Operations
Common Functions
▶ Length[L] — number of elements
▶ Total[L] — sum
▶ Max[L] — maximum
▶ Min[L] — minimum
▶ Mean[L] — average
Example
L = {5,2,8,1,9}
Length[L]
Total[L]
Max[L]
Min[L]
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 40 / 126
Lists in Plotting
ListPlot
ListPlot[{1,4,9,16,25}]
Coordinate Pairs
points = {{1,2},{2,4},{3,9},{4,16}}
ListPlot[points]
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 41 / 126
Summary
List Generators
Function Use
{...} Manual lists
Range Numeric sequences
Table General generation
NestList Iterative processes
Exercises
1 Create the first 10 cubes.
2 Create a 5 × 5 identity matrix using Table.
3 Compute iterations of xn+1 = cos(xn ) starting at x0 = 0.5.
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 42 / 126
Introduction to Plotting in Mathematica
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 43 / 126
Introduction to Plotting
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 44 / 126
Basic 2D Plotting: First Example
10
x
−4 −2 2 4
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 45 / 126
Plotting a More Complex Function: Example
(︀ )︀
Graphing f (x) = sin 𝜋x(3 − x) on 0 ≤ x ≤ 3
Plot [ Sin [ Pi x (3 - x ) ] , {x , 0 , 3} ]
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 46 / 126
Plotting Multiple Functions on One Graph
Syntax for Multiple Functions
To plot several functions together, provide a list of functions as the first
argument:
Plot [{ f1 [ x ] , f2 [ x ] , f3 [ x ] , ...} , {x , xmin ,
xmax }]
Example
Plot [{ Sin [ x ] , Cos [ x ]} , {x , -2 Pi , 2 Pi }]
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 49 / 126
The Show Function: Combining Plots
Definition (Show)
Show combines multiple graphics objects (plots) into a single output. This
is useful for overlaying plots created with different options.
This overlays the three plots, respecting the options from each.
Important
Options in Show (like PlotRange) override the options from the individual
plots.
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 50 / 126
Advanced Styling: Filling
The Filling Option
Filling shades the area between a curve and a reference (axis, another curve, or a
constant).
▶ Filling -> Bottom fills to the bottom of the plot.
▶ Filling -> Top fills to the top.
▶ Filling -> {1 -> {2}} fills between curve 1 and curve 2.
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 51 / 126
Specialized Plots: ListPlot
ListPlot for Discrete Data
ListPlot is used to plot individual data points, not continuous functions.
points = {{1, 2}, {2, 3}, {3, 5}, {4, 8}, {5, 12}};
ListPlot[points,
PlotStyle -> {Red, PointSize[Medium]}, AxesLabel -> {"x", "y"}]
Related Functions
▶ ListLinePlot connects the points with lines.
▶ ListPlot3D for 3D data points.
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 52 / 126
Specialized Plots: BarChart and PieChart
Mathematica includes many functions for statistical and data visualization.
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 53 / 126
Introduction to 3D Plotting: Plot3D
Basic 3D Example
Plot3D[x^2 + y^2, {x, -3, 3}, {y, -3, 3}]
Multiple Surfaces
Just like in 2D, you can plot multiple surfaces by providing a list:
Plot3D [{ x ^2 + y ^2 , 5 - x ^2 - y ^2} , {x , -3 ,
3} , {y , -3 , 3}]
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 54 / 126
Customizing 3D Plots
Common 3D Plot Options
Many 2D options work in 3D, plus some 3D-specific ones:
▶ ColorFunction -> "Rainbow" : Colors the surface by height.
▶ Mesh -> None : Removes the grid lines on the surface.
▶ PlotPoints -> 50 : Increases resolution (slower but smoother).
▶ Boxed -> False : Removes the bounding box.
▶ AxesLabel -> {"x", "y", "z"} : Labels all three axes.
Customized 3D Example
Plot3D[Sin[x y], {x, -3, 3}, {y, -3, 3},
ColorFunction -> "Rainbow",
Mesh -> None,
AxesLabel -> {"x", "y", "z"},
PlotPoints -> 50]
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 55 / 126
Example: A Specific 3D Function
Defining and Plotting a Custom Function
f[x_, y_] := x^2 y^2 Exp[-(x^2 + y^2)];
Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}]
2 +y 2 )
This defines and plots f (x, y ) = x 2 y 2 e −(x .
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 56 / 126
Contour and Density Plots
ContourPlot
ContourPlot shows level curves (lines of constant value) of a function f (x, y ).
DensityPlot
DensityPlot visualizes a function by coloring regions based on their value (like a
heat map).
Use Case
Contour and density plots are excellent for visualizing functions of two variables
without the complexity of a full 3D surface.
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 57 / 126
Parametric Plots
ParametricPlot (2D)
Plots curves defined parametrically as (x(t), y (t)).
ParametricPlot3D (3D)
Plots curves or surfaces defined parametrically in 3D.
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 58 / 126
Interactive Plots with Manipulate
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 60 / 126
Exercises
sin(x 3 )
1 Plot the function f (x) = on 0 ≤ x ≤ 1 with:
x3
a) No options (the default).
b) PlotRange -> All
c) PlotRange -> All, AspectRatio -> Automatic
What differences do you observe?
2 Create a plot containing y = x 2 and y = x 5 over 0 ≤ x ≤ 2 with:
a) No options.
b) PlotRange -> All
c) PlotRange -> {0,2} (what happens to x 5 ?)
d) PlotStyle -> {Red, Blue}
e) PlotStyle -> {{Red, Thick}, {Blue, Thick}}
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 61 / 126
Exercises
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 62 / 126
Introduction to Solving Equations
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 63 / 126
Solving Equations: Syntax
Solve[equation, variable]
Example:
Solve [ x ^2 - 4 == 0 , x ] (* Returns {{ x -> -2} , { x
-> 2}} *)
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 64 / 126
Solving Algebraic Equations: Examples
Single Equations
Solve finds exact symbolic solutions when possible.
Solve[2x + 3 == 0, x] Solve[x^2 - 9 == 0, x]
Cubic Equation
Solve 2x 3 + 5x 2 − 4x − 3 = 0:
Solve[2x^3 + 5x^2 - 4x - 3 == 0, x]
Solve [{ x + y == 10 , 2 x - y == 5} , {x , y }]
Solve [{ x + y == 5 , x - y == 1} , {x , y }]
Solve[x^3 - 2 == 0, x] NSolve[x^3 - 2 == 0, x]
Numerical Precision
To get more digits, specify precision:
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 67 / 126
The FindRoot Function
Purpose
FindRoot finds a numerical root of an equation starting from an initial guess. It is
useful when:
▶ No closed-form solution exists (e.g., cos(x) = x).
▶ You only need one root near a specific point.
▶ Solve or NSolve are too slow or fail.
Output: {x → 0.618034}
Solve cos(x) = x near x = 1:
FindRoot[Cos[x]
T/Birhan Abraha, PhD (AKU) == x, {x, 1}] to Mathematica
Introduction March 12, 2026 68 / 126
Working with Solutions: Replacement Rules
{{x -> a1, y -> b1}, {x -> a2, y -> b2}, ...}
Complete Workflow
1. Define equation. 2. Solve it, storing the result. 3. Use /. to substitute solutions into
expressions.
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 69 / 126
Domains and Conditions
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 70 / 126
Common Mistakes and Summary
Quick Reference
Function Best Used For...
Solve Exact symbolic solutions
NSolve Numerical approximations
FindRoot Numerical root near a guess
Reduce Finding solution conditions
/. (ReplaceAll) Substituting solutions
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 71 / 126
Polynomial Algebra: Core Functions
Command Purpose
PolynomialQ[poly, x] Tests if poly is a polynomial in x
Variables[poly] Lists all independent variables
Coefficient[poly, x^n] Extracts coefficient of x n
CoefficientList[poly, x] List of coefficients (constant term upward)
Expand[poly] Expands products and powers
Factor[poly] Factors over integers
Collect[poly, x] Groups terms by powers of x
PolynomialQuotient[p,d,x] Quotient of polynomial division
PolynomialRemainder[p,d,x] Remainder of polynomial division
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 72 / 126
Polynomial Examples: Coefficients
Extracting Coefficients
poly = x^3 - 5x^2 + y + 3x y^2 - 7y^3;
▶ Coefficient of x: Coefficient[poly, x, 1] → 3y 2
▶ Coefficient of y 2 : Coefficient[poly, y, 2] → 3x
▶ Coefficient of xy 2 : Coefficient[poly, x*y^
2] → 3
Coefficient List
poly1 = (x + 1)^10;
CoefficientList[poly1, x]
{1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1}
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 73 / 126
Polynomial Examples: Factoring
Collecting Terms
poly = 1 + 2x + 3y + 4xy + 5x^2 y + 6x y^2 + 7x^2 y^2;
Collect[poly, x]
Factoring
Factor[x^8 - 41x^4 + 400]
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 74 / 126
Rational Functions
Key Commands
▶ Numerator[expr] and Denominator[expr]
▶ Cancel[expr]
▶ Together[expr]
▶ Apart[expr]
▶ ExpandNumerator[expr]
▶ ExpandDenominator[expr]
Examples
Cancel[(x^2 + 5x + 6)/(x^2 + 3x + 2)]
Together[1/(x+1) + 2/(x^2-1)]
Apart[(x^2+5x)/(x^4 + x^3 - x - 1)]
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 75 / 126
Trigonometry: Basic Functions
Examples
Sin[Pi/4]
Cos[Pi/3]
Tan[Pi/6]
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 76 / 126
Trigonometric Simplification
Examples
Simplify [ Sin [ x ]^2 + Cos [ x ]^2]
Useful Functions
▶ TrigExpand
▶ TrigReduce
▶ TrigFactor
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 77 / 126
Solving Trigonometric Equations
Exact Solutions
Solve [ Sin [ x ] == 1/2 , x ]
Result {︂ }︂
𝜋 5𝜋
x → + 2𝜋C [1], x → + 2𝜋C [1]
6 6
Numerical Solution
FindRoot [ Sin [ x ] == 0.5 , {x ,1}]
Result
{x → 0.523599}
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 78 / 126
Graphing Trigonometric Functions
Plot Example
Plot [{ Sin [ x ] , Cos [ x ]} , {x , -2 Pi , 2 Pi } ,
PlotLegends -> { " sin ( x ) " , " cos ( x ) " } ,
AxesLabel -> { " x " , " y " }]
Modified Functions
Plot [{ Sin [ x ] , 2 Sin [ x ] , Sin [ x + Pi /2]} , {x ,
0 , 2 Pi }]
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 79 / 126
Summary
Key Ideas
▶ Polynomial manipulation: Expand, Factor, Collect
▶ Rational expressions: Cancel, Together, Apart
▶ Trigonometric identities: Simplify, TrigExpand
▶ Equation solving: Solve, NSolve, FindRoot
Exercises
1 Factor x 6 − 64.
x 2 +3x+2
2 Simplify x 2 +4x+3
.
2 1−cos 2x
3 Verify sin x = 2 .
4 Solve cos x = 0.3 for x ∈ [0, 2𝜋].
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 80 / 126
Overview of Calculus in Mathematica
Key Principle
Mathematica performs calculus symbolically by default. Use N[...] or
NIntegrate for numerical approximations.
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 81 / 126
Limits in Mathematica
Basic Limit Syntax
Limit[f[x], x -> a] computes lim f (x)
x→a
One-Sided Limits
Use the Direction option:
▶ Direction -> "FromAbove" or Direction -> -1 for the left-hand limit
(approaching from below).
▶ Direction -> "FromBelow" or Direction -> +1 for the right-hand limit
(approaching from above).
Note: The Direction option can be confusing. Remember: -1 means ”from below” on
the number line, which is the left-hand limit.
|x|
Example: lim
x→0 x
Limit[Abs[x]/x, x -> 0, Direction -> "FromAbove"] →1
Limit[Abs[x]/x, x -> 0, Direction -> "FromBelow"] → −1
Limit[Abs[x]/x, x -> 0] → Indeterminate
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 82 / 126
Introduction to Differentiation
Basic Example
D[x^2 + 3x + 5, x] (* 2x + 3 *)
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 83 / 126
Higher-Order and Partial Derivatives
1 Second and Higher Derivatives
D [ E ^x , x ] (* E ^ x *)
D [ E ^x , {x , 2}] (* Second derivative : E ^ x *)
D [ x ^5 , {x , 3}] (* Third derivative : 60 x ^2 *)
2 Partial Derivatives
D [ x ^2 y + Sin [ x y ] , x] (* Treat y as constant :
2 xy + y Cos [ x y ] *)
D [ x ^2 y + Sin [ x y ] , y] (* Treat x as constant :
x ^2 + x Cos [ x y ] *)
What is an Integral?
The integral represents the area under a curve (definite integral) or the
antiderivative (indefinite integral).
Basic Examples
Integrate[3x^2 + 2x + 1, x] (* x^3 + x^2 + x *)
Integrate[3x^2 + 2x + 1, {x, 0, 1}] (* 3 *)
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 86 / 126
Definite Integrals and Area
Applications
∫︁ b
▶ Area between curves: |f (x) − g (x)| dx
a
∫︁ b
▶ Volume of revolution: 𝜋 [f (x)]2 dx (disk method)
a
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 87 / 126
Applications: Area and Volume
∫︁ b
Area between curves: Area= |f (x) − g (x)| dx
a
Area between f (x) = x and g (x) = x 2 on 0 ≤ x ≤ 1
Integrate [ Abs [ x - x ^2] , {x , 0 , 1}] (* 1/6 *)
∫︁ b
Volume of revolution (Disk method) V = 𝜋 [f (x)]2 dx
a
Volume of solid formed by rotating y = x 2 around the x-axis from x = 0
to x = 1:
Integrate [ Pi ( x ^2) ^2 , {x , 0 , 1}] (* Pi /5 *)
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 88 / 126
Exact vs. Numerical Integration
Important
Mathematica will indicate if an integral diverges (does not converge to a
finite value).
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 90 / 126
Multivariate Calculus
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 91 / 126
Multiple Integrals
Syntax for Multiple Integrals
∫︀Integrate[f[x,y], {x, xmin, xmax}, {y, ymin, ymax}] computes
xmax ∫︀ ymax
xmin ymin f (x, y ) dy dx.
0 ≤ x ≤ 2, 0 ≤ y ≤ x, 0 ≤ z ≤ xy
Mathematica Implementation
Integrate[x y z, {x, 0, 2}, {y, 0, x}, {z, 0, x y}]
Result: 4
Interpretation
The limits of integration can depend on outer variables. Here:
▶ y ranges from 0 to x.
▶ z ranges from 0 to xy .
This defines a 3D region.
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 93 / 126
Applied Calculus
Area Between Curves
General Approach
1 Find intersection points of the curves.
2 Integrate the difference (top function minus bottom function)
between intersections.
Integrate[Abs[x
T/Birhan Abraha, PhD (AKU)
- x^2],Introduction
{x, 0,to Mathematica
1}] (* Also 1/6 *)
March 12, 2026 94 / 126
Arc Length
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 95 / 126
Summary: Calculus in Mathematica
Quick Reference
Operation Command
Limit Limit[f[x], x -> a]
One-sided limit Limit[f[x], x -> a, Direction -> -1]
Derivative (1st) D[f[x], x] or f’[x]
Higher derivative D[f[x], x, n]
Partial derivative D[f[x,y], x]
Gradient Grad[f[x,y], x,y]
Indefinite integral Integrate[f[x], x]
Definite integral Integrate[f[x], x,a,b]
Numerical integral NIntegrate[f[x], x,a,b]
Multiple integral Integrate[f[x,y], x,a,b, y,c,d]
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 96 / 126
Practical Exercises: Limits and Derivatives
Limits
Compute the following limits.
Derivatives
x2 − 4
1 Find the derivatives of the
1 lim following functions.
x→2 x − 2
1 f (x) = x 3 + 2x 2 − 5x
sin x
2 lim 2 g (x) = e x sin x
x→0 x 3 h(x) = ln(x 2 + 1)
3x 2 + 5
3 lim 2 2 Find the critical points of
x→∞ x − 1
sin x f (x) = x 4 − 4x 3 + 4x 2 .
4 lim
x→0 x
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 97 / 126
Practical Exercises: Integrals
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 98 / 126
Practical Exercises: Applications of Calculus
Graphing Functions
1 Plot f (x) = x 3 − 3x
2 Plot g (x) = sin x
3 Plot both functions on the same axes.
Optimization
Find the maximum and minimum values of
f (x) = x 3 − 6x 2 + 9x + 1
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 99 / 126
Ordinary Differential Equations (ODEs)
Key Terminology
▶ Order: Highest derivative appearing in the equation.
▶ Degree: Power of the highest derivative after rationalization.
▶ Linear ODE: an (x)y (n) + · · · + a1 (x)y ′ + a0 (x)y = g (x)
Example
For y ′′ + 3y ′ + 2y = 0
▶ Order: 2, Degree: 1, Linear: Yes
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 100 / 126
Solving ODEs in Mathematica
Main Commands
DSolve Finds symbolic solutions.
NDSolve Computes numerical solutions.
General Syntax
DSolve [ ode , y [ x ] , x ]
Important Syntax
▶ Equations use == DSolve [{ ode , conditions
▶ Derivatives are written as },
y’[x], y’’[x] y[x], x]
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 101 / 126
First-Order ODE Examples
Separable Equation
dy
Solve = xy
dx
DSolve [y ’[ x ] == x y [ x ] , y [ x ] , x ]
Solution:
2 /2
y [x] = C [1]e x
Solution:
1
y [x] = e −2x C [1] + e x
3
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 102 / 126
Initial Value Problems
Solution Solution
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 103 / 126
Second-Order Linear ODEs
Homogeneous Equation
y ′′ − 3y ′ + 2y = 0
Nonhomogeneous Equation
y ′′ + 4y = sin x
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 104 / 126
Systems of Differential Equations
Solution:
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 105 / 126
Numerical Solution Using NDSolve
Example
y ′ = y − x, y (0) = 1
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 106 / 126
Applications od ODE
Solution:
T [t] = Tenv + C [1]e −kt
DSolve [{ T ’[ t ] == -k ( T [ t ] - Tenv ) ,
T [0] == T0 } , T [ t ] , t ]
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 107 / 126
Logistic Growth Model
dy (︁ y )︁
= ry 1 −
dt K
DSolve [y ’[ t ] == r y [ t ] (1 - y [ t ]/ K ) , y [ t ] , t ]
With y (0) = y0 :
Ky0 e rt
y (t) =
K + y0 (e rt − 1)
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 108 / 126
Summary
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 109 / 126
Exercises
1 Solve y ′ + 2xy = 0.
2 Find the solution of y ′ = y cos x with y (0) = 1.
3 Solve y ′′ + 4y ′ + 4y = 0.
4 Solve y ′′ + 9y = cos(2x).
5 Use NDSolve for y ′ = sin(xy ), y (0) = 1.
6 Solve the system
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 110 / 126
Introduction to Linear Algebra
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 111 / 126
Vectors: Creation and Basic Operations
Creating Vectors
A vector is simply a list of numbers.
u = {1 , 2 , 3};
v = {4 , 5 , 6};
w = {7 , 8 , 9 , 10}; (* vectors can have any length
*)
Viewing Matrices
Use MatrixForm to display matrices in traditional notation:
⎛ ⎞
(︂ )︂ 9 4 2
1 2
A // MatrixForm A= , B = ⎝2 9 3⎠
3 4
B // MatrixForm 0 1 4
Element-wise Operations
These operations act on each element independently:
▶ Addition/Subtraction: A + B, A - B
▶ Scalar Multiplication: 2 * A
▶ Element-wise Multiplication (Schur/Hadamard product): A * B
▶ Element-wise Power: A^2 squares each element (not matrix
multiplication!)
(︂ )︂
1 2
Example with Matrix A =
3 4
A = {{1,2},{3,4}};
2 * A (* {{2,4},{6,8}} *)
A^2 (* {{1,4},{9,16}} - element-wise *)
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 114 / 126
Matrix Operations
Core Linear Algebra Operations
▶ Matrix Multiplication (Dot Product): A . B (uses a dot, not an
asterisk!)
▶ Matrix Power: MatrixPower[A, n] for An
▶ Transpose: Transpose[A] or AT
▶ Trace: Tr[A] (sum of diagonal elements)
▶ Determinant: Det[A]
▶ Inverse: Inverse[A]
▶ Row Reduce: RowReduce[A] (reduced row echelon form)
Critical Distinction
▶ A * B is element-wise multiplication.
▶ A . B is matrix multiplication (dot product). Mixing these up is a
very common mistake!
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 115 / 126
Matrix Operations: Examples
▶ Element-wise A * B: ▶ Determinant:
⎛ ⎞ Det[A] = 269
18 32 2
⎝16 27 12⎠
0 4 0
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 116 / 126
Accessing Matrix Elements
Indexing in Matrices
Matrices use 1-based indexing, just like vectors. Use double brackets [[
]]
Extracting Parts
▶ First[A], Last[A], Take[A, n], etc., work as with lists.
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 117 / 126
Solving Systems of Linear Equations
Matrix Form of a Linear System
A system of linear equations can be written as:
Ax = b
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 119 / 126
Eigenvalues and Eigenvectors
Definition
For a square matrix A, a scalar 𝜆 and a non-zero vector v satisfying
Av = 𝜆v
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 121 / 126
Matrix Norms and Properties
Matrix Norms
Various norms can be computed:
Norm [ A ] (* 2 - norm ( largest singular value ) *)
Norm [A , 1] (* 1 - norm ( maximum column sum ) *)
Norm [A , Infinity ] (* Infinity - norm ( maximum row
sum ) *)
Norm [A , " Frobenius " ] (* Frobenius norm ( sqrt of sum
of squares ) *)
MatrixPlot
MatrixPlot[A] creates a visual representation of a matrix, with colors
representing values.
A = RandomReal [1 , {10 , 10}];
MatrixPlot [ A ]
ArrayPlot
Similar to MatrixPlot, but often used for binary or integer arrays.
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 123 / 126
Summary: Linear Algebra in Mathematica
Quick Reference
Operation Command
Vector/Matrix creation {1,2,3}, {{1,2},{3,4}}
Display //MatrixForm
Addition/Subtraction A + B, A - B
Scalar multiplication c * A
Element-wise multiplication A * B
Matrix multiplication A . B
Transpose Transpose[A]
Determinant Det[A]
Inverse Inverse[A]
Solve linear system LinearSolve[A, b]
Eigenvalues Eigenvalues[A]
Eigenvectors Eigenvectors[A]
Row reduce RowReduce[A]
Matrix rank MatrixRank[A]
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 124 / 126
Exercises
1 Define the vectors u = {1, -2, 3} and v = {-2, 1, 2}. Compute:
a) u+v
b) 3u − 2v
c) u · v (Dot product)
d) u × v (Cross product)
(︂ )︂ (︂ )︂
1 2 2 0
2 Define the matrices A = and B = . Compute:
3 4 1 3
a) A + B
b) A . B (Matrix multiplication)
c) A * B (Element-wise multiplication)
d) Det[A] and Inverse[A]
3 Solve the linear system using Solve and LinearSolve:
⎧
⎨x + 2y − z = 3
⎪
2x − y + 3z = 8
⎪
3x + y − 2z = 1
⎩
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 125 / 126
Exercises (Contd)
⎛ ⎞
4 1 0
4 For the matrix C = ⎝1 3 −1⎠:
0 −1 2
a) Find its eigenvalues and eigenvectors using Eigenvalues and
Eigenvectors.
b) Verify that for the first eigenvalue-eigenvector pair, C v = 𝜆v.
c) Compute the characteristic polynomial using
CharacteristicPolynomial.
5 Hilbert Matrices and Precision:
a) Create a 5 × 5 Hilbert matrix: H = HilbertMatrix[5].
b) Compute Det[H] and Inverse[H].
c) Convert the inverse to a decimal using N[...]. What do you observe
about the magnitude of the entries?
T/Birhan Abraha, PhD (AKU) Introduction to Mathematica March 12, 2026 126 / 126