Introduction
Introduction
Introduction
Lectures:
Monday 1-2, Tuesday 3-4, Friday 3-4
Support Classes and Assessments discussed tomorrow
but start next week (week 2)
Office hours: do not really have any
talk to me after lecture or send me an email
MA261: Mathematical Modelling and Numerical Analysis
General remarks:
I no lecture capture
I lecture mixture of slides and blackboard
I lecture notes and slides used in lecture provided on Moodle
I lecture notes will be updated periodically
I Aim: material from each week uploaded end of each week
I examples in lecture use Python, some scripts will be uploaded
Assessment:
I exam: in summer on theory
I coursework: mixture of theory and practical work
I practical work can be done in MATLab or Python
I some templates might be provided if required
(but possibly only in MATLab, but the Python scripts from
the lecture could serve as templates as well)
I for the practical part submitting in pairs is allowed but theory
part needs to be submitted individually
I deadline for coursework is Thursday at 12 weeks 3,5,7, and 9
(all worth the same 25% of the coursework’s 50%)
Assignments
Presenting results: plots are often better then tables but don’t put
too much into one plot and think about the form of your plots e.g.
I a y-axis between 10−20 and 1020 and a more or less straight
line is not very enlightning - reduce the range to 10−8 and 102
for example.
I for comparing the error plots between two methods the axis
should have the same range e.g. axis([0 1 1e-6 10])
I consider using a log scale on either or both axes
Relate results to lecture, e.g., mention a convergence proofs...
Avoid code duplication - if you are plotting results for different test
problem reuse code as much as possible
Always include m codes. Not every modification of the template is
required, a short remark that you changed the definition of the
function ‘f(y)‘ for example is good enough.
Look at what the printer did with your output - can the plots be
read without microscope...
Screenshots of code are hard to read! Screenshots of graphs even
more so...
Mathematical Modelling
Possible Objectives
I Developing scientific understanding
through quantitative expression of current knowledge of a
system (as well as displaying what we know, this may also
show up what we do not know)
I test the effect of changes in a system
I aid decision making (managers, planners, politicians)
Mathematical Modelling
Types of models
I Static models: soap bubble
I Discrete models: change of population from year to year
I Dynamic models: ODEs
I Stochastic models: include some form of randomness in for
example a given dynamic model
I Spatial and temporal models: PDEs for fluid flow, acoustics
Mathematical Modelling
u(t)
c
u(t)
1 1
c
0
0 t t0
MA228 Numerical Analysis: Problems with error in data
Consider
1.2969 0.8648 x1 0.86419999
= =: b.
0.2161 0.1441 x2 0.14400001
x1 0.9911
with solution = .
x2 −0.4870
0.8642
Due to some error, we solve with right hand side b̄ =
0.1440
which is a relative error less than 10−7 .
MA228 Numerical Analysis: Problems with error in data
Consider
1.2969 0.8648 x1 0.86419999
= =: b.
0.2161 0.1441 x2 0.14400001
x1 0.9911
with solution = .
x2 −0.4870
0.8642
Due to some error, we solve with right hand side b̄ =
0.1440
−7 .
which is a relative error less than 10
x̄1 2
The solution to the new problem is = , which
x̄2 −2
is a relative error of more than 100%.
MA261: making predictions...
Example: predicting population based on data 1910 − 1990 to
estimate population in 2000, 2010, 1900.
Polynomial interpolation (9 points fitted with 8th order polynomial)
MA261: making predictions...
Example: predicting population based on data 1910 − 1990 to
estimate population in 2000, 2010, 1900.
Polynomial interpolation (9 points fitted with 8th order polynomial)
MA228 Numerical Analysis: making predictions...
Example: predicting population based on data 1910 − 1990 to
estimate population in 2000, 2010, 1900.
Polynomial interpolation
1
Error as function of subinterval size h: 0.1
0.01
0.01
0.0001
1e-06
0.001
error
error
1e-08
0.0001
1e-10
1e-12
Trapezoidal Rule 1e-05 Trapezoidal Rule
Simpson rule Simpson rule
1e-14
2 point Gauss 2 point Gauss
Romberg Romberg
1e-16 1e-06
0.001 0.01 0.1 1 0.001 0.01 0.1 1
h h
MA228 Numerical Analysis: varying schemes and problems
Z1 Z1
1 3√
dx = ln(2) x dx = 1
x +1 2
0 0
1
Error as function of subinterval size h: 0.1
0.01
0.01
0.0001
1e-06
0.001
error
error
1e-08
0.0001
1e-10
1e-12
Trapezoidal Rule 1e-05 Trapezoidal Rule
Simpson rule Simpson rule
1e-14
2 point Gauss 2 point Gauss
Romberg Romberg
1e-16 1e-06
0.001 0.01 0.1 1 0.001 0.01 0.1 1
h h
1e-06
0.001
error
error
1e-08
0.0001
1e-10
1e-12
1e-05
1e-14
1e-16 1e-06
1 10 100 1000 1 10 100 1000
Function evaluations Function evaluations
Solving an ODE
yn ≈ y (tn )
yn ≈ y (tn )
where
m
X 1 (k)
Pm (x) = y (x0 )(x − x0 )k ,
k!
k=0
where
m
X 1 (k)
Pm (x) = y (x0 )(x − x0 )k ,
k!
k=0
800
600
y(t)
400
200
-200
-400
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5
t
Solving an ODE (final part of course)
Explicit or Forward Euler Method: yn+1 = yn + hf (tn , yn )
(note that y0 is given).
20
10
0
y(t)
-10
-20
-30
-40
-50
-60
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5
t
Solving an ODE (final part of course)
Explicit or Forward Euler Method: yn+1 = yn + hf (tn , yn )
(note that y0 is given).
0.8
y(t)
0.6
0.4
0.2
0
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5
t
Solving an ODE (final part of course)
Explicit or Forward Euler Method: yn+1 = yn + hf (tn , yn )
(note that y0 is given).
0.8
0.7
0.6
y(t)
0.5
0.4
0.3
0.2
0.1
0
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5
t
Solving an ODE
Theorem (Taylor Theorem (Version 1))
Let y ∈ C m (a, b) and x0 ∈ (a, b) be given. Then there exist a
function ωm : R → R with lim ωm (x) = 0, so that
x→x0
where
m
X 1 (k)
Pm (x) = y (x0 )(x − x0 )k ,
k!
k=0
1
y(t)
0.5
-0.5
-1
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5
Solving an ODE (final part of course)
Implicit or Backward Euler Method: yn+1 − hf (tn+1 , yn+1 ) = yn
(note that y0 is given).
y1 − hf (t1 , y1 ) = y0 , y2 − hf (t2 , y2 ) = y1 , y3 − hf (t3 , y3 ) = y2 , . . .
Problem: find root of Fn (y ) = y − hf (tn+1 , y ) − yn (discussed in
lecture)
Example: f (t, y ) = −50(y − cos(t)) − sin(t)
h = 0.1
2
forward Euler
backward Euler
exact
1.5
1
y(t)
0.5
-0.5
-1
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5
Solving an ODE (final part of course)
Implicit or Backward Euler Method: yn+1 − hf (tn+1 , yn+1 ) = yn
(note that y0 is given).
y1 − hf (t1 , y1 ) = y0 , y2 − hf (t2 , y2 ) = y1 , y3 − hf (t3 , y3 ) = y2 , . . .
Problem: find root of Fn (y ) = y − hf (tn+1 , y ) − yn (discussed in
lecture)
Example: f (t, y ) = −50(y − cos(t)) − sin(t)
h = 0.05
2
forward Euler
backward Euler
exact
1.5
1
y(t)
0.5
-0.5
-1
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5
Solving an ODE (final part of course)
Implicit or Backward Euler Method: yn+1 − hf (tn+1 , yn+1 ) = yn
(note that y0 is given).
y1 − hf (t1 , y1 ) = y0 , y2 − hf (t2 , y2 ) = y1 , y3 − hf (t3 , y3 ) = y2 , . . .
Problem: find root of Fn (y ) = y − hf (tn+1 , y ) − yn (discussed in
lecture)
Example: f (t, y ) = −50(y − cos(t)) − sin(t)
h = 0.025
2
forward Euler
backward Euler
exact
1.5
1
y(t)
0.5
-0.5
-1
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5
Solving an ODE
Theorem (Convergence result (next week))
If the exact solution Y satisfies Y ∈ C 2 (0, T ) then
max |y (tn ) − yn | ≤ Ch
n=0,...,N
later in lecture
1
0.1
0.01
approximation error
0.001
0.0001
1e-05
1e-06
1e-07
i N yN |y (T ) − yN |
0 101 [1.207662 1.227752] 0.308212
1 201 [1.101395 1.105955] 0.146654
2 401 [1.050037 1.051122] 0.071534
3 801 [1.024848 1.025113] 0.035328
4 1601 [1.012381 1.012446] 0.017555
5 3201 [1.006179 1.006196] 0.008751
i N yN |y (T ) − yN |
0 10001 [-2.00707197e+07 5.08075873e+08] 508472148.289626
1 20001 [14884.248122 22777.185506] 27207.824258
2 40001 [131.598722 145.95242 ] 195.108253
3 80001 [11.637561 11.9422 ] 15.260715
4 160001 [3.422772 3.444954] 3.442038
5 320001 [1.851583 1.854576] 1.206438
Forward Euler method for mass-spring problem
2 10
0 0
−2 −10
−2 0 2 −10 0 10
Backward Euler method for mass-spring problem
1 1
0 0
−1 −1
−1 0 1 −1 0 1
i N yn |y (T ) − yN |
0 101 [0.814386 0.827934] 0.2531
1 201 [0.904188 0.907932] 0.132877
2 401 [0.951364 0.952347] 0.06809
3 801 [0.975503 0.975755] 0.034467
4 1601 [0.987707 0.987771] 0.01734
5 3201 [0.993842 0.993859] 0.008697
Observation
1 1
0 0
−1 −1
−1 0 1 −1 0 1
i N yn |y (T ) − yN |
0 101 [1.001066 0.998932] 0.001509
1 201 [1.000262 0.999737] 0.000371
2 401 [1.000065 0.999935] 9.2e-05
3 801 [1.000016 0.999984] 2.3e-05
4 1601 [1.000004 0.999996] 6e-06
5 3201 [1.000001 0.999999] 1e-06
Observation