1  Introduction

Lecture 1: Introduction to Math5485

Published

September 9, 2026

Overview
  1. Syllabus, Canvas, website, and admin;
  2. Intro to notebooks;
  3. Overview of Math5485;
  4. Intro to Numerical Analysis;
  5. Exercises

These lecture notes are mainly a record of what we discussed in class. They should not be used as a replacement for attending lectures or reading books. Please let me know if you find any errors or have any questions about the material.

You can use the Hypothesis commenting system available on the right side panel (you can login with your U/Google account). This allows you annotate the notes (private) and leave comments or reply to other people’s comments (public).

I encourage you to download the lecture notes and play around with the Julia code.

1.1 Notebooks

This website is created using Jupyter Notebooks. They allow you to include Markdown, \(\LaTeX\), and Julia (as well as python and other languages).

Tip

Follow the steps in installing-julia.html and A1 to learn about notebooks and Julia.

Notebooks are made up from “cells”.

  • A adds a cell above the currently selected cell,
  • B adds a cell below,
  • M changes the cell from Julia to markdown,
  • Y changes the cell from markdown to Julia,
  • Double click or enter to see the syntax and edit cells,
  • Press ctrl+enter to exit edit mode,

Exercise 1.1

Add a new markdown cell below this one and write “Hello world!”

1.2 Markdown

Text in this cell can be bold, italic, bold italic, quotes

“The only source of knowledge is experience”
– Einstein

Preformatted text,
    useful for
pseudocode
  • Bullet points
    • level 2 bullet points
    • etc..
  • Another point
You can also use normal html formatting if you are familiar with that…

Markdown cheat sheet: link (opens in a new tab)

1.3 \(\LaTeX\)

\(\LaTeX\) allows you to display math: e.g. \(\pi \approx \frac{22}{7}\) and \[f(x) = f(a) + f'(a) (x - a) + \frac{1}{2} f''(a) (x-a)^2 + R(x).\]

Multi-line equations are also possible:

\[ \begin{align} \int_a^b f(x) \mathrm{d}x % &\approx \int_a^b p_n(x) \mathrm{d}x \nonumber \\ % &= \sum_{j=0}^n w_j f(x_j) \end{align} \tag{1.1}\]

\(\LaTeX\) cheat sheet: link (opens in a new tab)

Draw symbol to get \(\LaTeX\) syntax: link (opens in a new tab)

1.4 Julia

Code
1+1
2

You can use greek symbols in Julia code: type \pi and tab to get the symbol.

Code
π 
π = 3.1415926535897...

You can add comments with a #:

Code
# Define p
p = 22/7;

You can also use @show to print variables (which also prints the calculation):

Code
@show abs(π-p)/π;
abs(π - p) / π = 0.0004024994347707008

You can use println() to output variables (and you can also add text):

Code
println( "The relative error when approximating π by 22/7 is ", abs(π-p)/π)
The relative error when approximating π by 22/7 is 0.0004024994347707008

1.4.1 Arrays, vectors, and matrices

Arrays start at 1:

Code
a = [1 2 3 4 5]
1×5 Matrix{Int64}:
 1  2  3  4  5
Code
a[1]
1

Vectors:

Code
b = [2, 4, 6, 8]
4-element Vector{Int64}:
 2
 4
 6
 8

Vector of objects:

Code
c = [ a , b , "hello world" ]
3-element Vector{Any}:
 [1 2 … 4 5]
 [2, 4, 6, 8]
 "hello world"
Code
c[3]
"hello world"

Matrices

You can either specify the columns:

Code
X = [ [1, 4] [2, 5] ]
2×2 Matrix{Int64}:
 1  2
 4  5

Or the rows:

Code
Y = [ 1 2 ; 4 5 ]
2×2 Matrix{Int64}:
 1  2
 4  5

Linear Algebra

In order to use a certain package, you need to use the using keyword:

Code
using LinearAlgebra

Recall that

Code
X
2×2 Matrix{Int64}:
 1  2
 4  5
Code
det( X )
-3.0
Code
tr( X )
6
Code
(-1/3) * [ 5 -2 ; -4 1 ]
2×2 Matrix{Float64}:
 -1.66667   0.666667
  1.33333  -0.333333
Code
inv( X )
2×2 Matrix{Float64}:
 -1.66667   0.666667
  1.33333  -0.333333
Code
ϵ, v = eigen( X )
Eigen{Float64, Float64, Matrix{Float64}, Vector{Float64}}
values:
2-element Vector{Float64}:
 -0.4641016151377544
  6.464101615137754
vectors:
2×2 Matrix{Float64}:
 -0.806898  -0.343724
  0.59069   -0.939071
Code
v1 = v[1:2,1]; # gets the first column of v
norm( ( X - ϵ[1] * Diagonal([1, 1]) ) * v1 )
2.220446049250313e-16

1.4.2 Functions

Code
f = x -> cos( x );
f( π )
-1.0
Code
# vectorisation = entry-wise functuions --> use dot!
f.( [-π, 0, π] )
3-element Vector{Float64}:
 -1.0
  1.0
 -1.0
Code
# you can also specify the vectorisation at the start:
@. f( [-π, 0, π] )
3-element Vector{Float64}:
 -1.0
  1.0
 -1.0

In order to plot functions we need the Plots package and, in order to write \(\LaTeX\) in the titles and labels, we need LaTeXStrings.

Code
using Plots, LaTeXStrings
Code
g(x) = x/exp(x)
plot( g, -5, 1, label="hello" )
Code
X = -5:.01:1;
Y = X .* exp.(X) ;
 
plot( X, Y; 
    label = L"f(w) = w e^w", 
    xlabel = L"w", ylabel = "not latex", 
    title = "L\"\" is a LaTeX string and \"\" a normal string" ) 
Code
X = range(0, 10, length=100)
Y1 = @. sin(X) / X
Y2 = cos.(X)
plot( X, [Y1 Y2], 
        xlabel=L"x", 
        label=[L"\frac{\sin x}{x}" L"\cos x"], 
        linewidth=[4 2], 
        lc=[:green :blue]) 
Figure 1.1: Ploting two functions on one graph

In Figure 1.1, you can see two graphs!

Note

If you are looking at the code, don’t worry about the @fig-1 or the ::: {.callout-note} syntax - this adds the html/css elements so that the webpage looks nicer.

! is like “hold on” in Matlab (if you are familar with that!)

Code
f3(x) = 1 / (1 + x^2);
f4(x) = 1 / (1 + sin(x)^2);
plot(f3, -π, π, 
        lw=3, 
        label = L"f_1(x) = \frac{1}{1+x^2}");
plot!(f4, -π, π, 
        lw = 3, 
        label = L"f_2(x) = \frac{1}{1+\sin^2(x)}", 
        size = (600, 250), legend = :outertopright )
Figure 1.2: Ploting functions

1.5 Math 5485

  • Chapter 1: Basics of Numerical Analysis
  • Chapter 2: Solving Nonlinear Equations in 1d
  • Chapter 3: Polynomial Interpolation
  • Chapter 4: Numerical Integration
  • Chapter 5: Linear systems of equations

1.6 Chapter 1: Basics of Numerical Analysis

  • Absolute and relative error
  • Rate of convergence
  • Using plots to show rate of convergence

Suppose we approximate \(x\) with \(\widetilde{x}\). Here, \(x\) could be e.g. a root (or fixed point) of a function, the value of an integral, the solution of an ODE or PDE evaluated at a point, …. .

Definition 1.1 (Errors) We define:

\[\begin{align} \text{Actual error:} &\quad x - \widetilde{x} \\ \text{Absolute error:} &\quad |x - \widetilde{x}| \end{align}\]

And when \(x \neq 0\), the relative error is:

\[\begin{align} \text{Relative error:} \quad \frac{|x - \widetilde{x}|}{|x|} \end{align}\]

Example 1.1 If \(x = 1.5\) and \(\widetilde{x} = 1\), then the absolute error is \(0.5\) and the relative error is \(\frac{0.5}{1.5} = \frac13\).

If \(x = 1.5 \times 10^{42}\) and \(\widetilde{x} = 10^{42}\), then the absolute error is \(0.5 \times 10^{42}\) and the relative error is \(\frac13\).

If \(x = 1.5 \times 10^{-42}\) and \(\widetilde{x} = 10^{-42}\), then the absolute error is \(0.5 \times 10^{-42}\) and the relative error is \(\frac13\).

The relative error is a better measure for small or large \(x\):

Example 1.2 Approximating Planck’s constant \(6.62607015 \times 10^{-34} \text{m}^2 \text{kg } \text{s}^{-1}\) with \(0 \text{m}^2 \text{kg } \text{s}^{-1}\) would give an absolute error of \(\approx 6 \times 10^{-34}\) (which seems small) but a relative error of \(1\). In practice \(0\) is a bad approximation to Planck’s constant!

Definition 1.2 (Number of correct significant digits) Suppose \(x \not= 0\) is approximated by \(\widetilde{x}\). Then, we say this approximation is accurate to \(n\) significant digits if

\[\left| \frac{x-\widetilde{x}}{x} \right| \leq 5 \times 10^{-n}.\]

Example 1.3 Approximating \(e := \lim_{n\to\infty} \big( 1 + \frac1n \big)^n \approx 2.7182818.....\) with \(3, 2.7,\) and \(2.718\) gives

\[\begin{align} \left| \frac{e-\widetilde{x}}{e} \right| = 1.04 \times 10^{-1}, \quad 0.673 \times 10^{-2}, \quad 0.104 \times 10^{-3}, \end{align}\]

respectively.

Code
e = exp(1)
abs( (e-3)/e ), abs( (e-2.7)/e ), abs( (e-2.718)/e )
(0.10363832351432703, 0.006725508837105614, 0.00010367889601972718)

Remark 1.1 (Number of correct significant digits). Suppose \(x \not= 0\) is approximated by \(\widetilde{x}\). Some people say that this approximation is accurate to

\[\eta := - \log_{10} \left| \frac{x-\widetilde{x}}{x} \right|\]

significant digits.

Exercise 1.2

Compute \(\eta\) for approximating \(e\) with \(3\), \(2.7\), and \(2.718\).

We now consider a sequence of approximations \(x_n\) converging to \(x\). That is, for all \(\varepsilon > 0\), there exists \(N=N(\varepsilon)\) such that \(|x - x_n| < \varepsilon\) for all \(n > N\). In numerical analysis, we are interested in (i) whether our numerical schemes converge, and (ii) the rate of convergence:

Definition 1.3 (Rate of convergence) Suppose \(\varepsilon_n \geq 0\) and \((\varepsilon_n) \to 0\). Then, \(x_n \to x\) with rate \(O(\varepsilon_n)\) if there exist \(C\) and \(N\) such that

\[ |x - x_n| \leq C\varepsilon_n \]

for all \(n > N\). We also write \(x_n = x + O(\varepsilon_n)\).

Exercise 1.3

Show that \(\frac{n + \cos(n)}{n^2} = O(\frac1n)\) and \(\frac{n^2+3}{n^{42}} = O(\frac1{n^{40}})\).

When plotting graphs, \(O(n^{-k})\) decay (that is, algebraic decay) can be seen as straight lines on log-log plots (\(-k\) is the slope in such graphs):

Code
N = 1:100;
plot( N.^(-1) ;
    xlabel="n", xaxis=:log, yaxis=:log, 
    linestyle = :dot, lw=2, label = L"n^{-1}")
plot!( N.^(-2); 
    linestyle = :dot, lw=2, label = L"n^{-2}")
plot!( N.^(-5); 
    linestyle = :dot, lw=2, label = L"n^{-5}")

On the other hand, \(O(e^{-c N})\) (that is, exponential decay) can be seen as straight lines on a semi-log y plot (and \(-c\) is the gradient):

Code
plot( exp.(-N);
    xlabel="n", yaxis=:log, 
    linestyle = :dot, lw=2, label = L"e^{-n}")
plot!( exp.(-2 .* N ); 
    linestyle = :dot, lw=2, label = L"e^{-2n}")
plot!( exp.(-5 .* N ); 
    linestyle = :dot, lw=2, label = L"e^{-5n}")
TipTO-DO
  • Assignment 1: Due Wednesday (Install Julia),
  • Exercises (below)
  • (Sign-up to office hours if you like)

1.7 Exercises

Exercise 1.4 (Approximating Euler’s constant)

Let \(e\) denote Euler’s constant.

  1. \(e_N := \big( 1 + \frac{1}{N} \big)^N\) is an approximation \(e\). What is the error, absolute error, and relative error in approximating \(e\) with \(e_N\) for \(N = 1,2,...,10\)? What are the number of accurate digits in this approximation?
  2. What is the rate of convergence of \(e_N\) to \(e\)?

Exercise 1.5 (Approximating Euler-Mascheroni constant)

Euler-Mascheroni constant, \(\gamma\), is defined as the limit of \(\gamma_n = \sum_{k=1}^n \frac{1}{k} - \log n\) as \(n \to \infty\).

  1. What is the absolute error in approximating \(\gamma\) with \(\gamma_{1000}\)?
  2. What is the rate of convergence of \(\gamma_n\) to \(\gamma\)?
  3. [This was just so that we can remember some calculus and also rigorously prove the rate of convergence that we have seen above using a rigorous error estimate]
    Prove that \(|\gamma - \gamma_n| \leq \frac1n\).

Exercise 1.6 (Approximating π)

Assignment 1, Fall 2025, 30 pts The quantities

\[\begin{align} \pi_N := 4 \sum_{n=0}^N \frac{(-1)^n}{2n+1} \end{align}\]

approximate \(\pi\) by using the Taylor expansion of \(\arctan\) together with the fact that \(\pi = 4 \arctan(1)\).

Code
using Plots, LaTeXStrings

Nmax = 100;
Ninter = 1:Nmax;

# vectors of length Nmax
p = zeros( Nmax ); q = zeros( Nmax );
p[1] = 4 * ( 1 - 1/3 ) ;
q[1] = abs( p[1] - π );
for N in 2:Nmax
    p[N] = p[N-1] + 4 * (-1)^N/(2*N + 1);
    q[N] = abs( p[N] - π );
end

plot(p, legend=false, xlabel="N", title=L"\pi_N")

Based on the following graph, what is the rate of convergence of this particular approximation to \(\pi\)? Why do we use a log-log scale for this graph?

Code
plot( q , xaxis=:log, yaxis=:log, xlabel=L"N", title="absolute error", legend=false)
plot!( Ninter.^(-1) , ls=:dash)
Timer
00:00
min