Scientific Computing Maastricht Science Program Week 6 Frans - - PowerPoint PPT Presentation

scientific computing
SMART_READER_LITE
LIVE PREVIEW

Scientific Computing Maastricht Science Program Week 6 Frans - - PowerPoint PPT Presentation

Scientific Computing Maastricht Science Program Week 6 Frans Oliehoek <frans.oliehoek@maastrichtuniversity.nl> The World is Dynamic Many problems studied in science are 'dynamic' change over time Examples: change of


slide-1
SLIDE 1

Scientific Computing

Maastricht Science Program

Week 6

Frans Oliehoek <frans.oliehoek@maastrichtuniversity.nl>

slide-2
SLIDE 2

The World is Dynamic

 Many problems studied in science are 'dynamic'

 change over time

 Examples:

 change of temperature  trajectory of a baseball  populations of animals  changes of price in stocks

  • r options

 Commonly modeled with differential equations

(Not to be confused with difference equations)

Visualization of heat transfer in a pump casing Heat is generated internally, cooled at the boundary → steady state temperature distribution.

slide-3
SLIDE 3

Recap Difference Equations

 Remember difference equations (week1, week5)

 e.g. polulation growth:  discrete time steps

 Now differential equations: continuous time

Pt=Pt−1+Δ Pt−1 Δ Pt−1=(b−d)Pt−1

slide-4
SLIDE 4

Differential Equations

 Simple growth of bacteria model:

 r – rate of growth  p – population size

r(t)=C p(t)

slide-5
SLIDE 5

Differential Equations

 Simple growth of bacteria model:

 r – rate of growth  p – population size

r(t)=C p(t)

Question to solve:

  • How many bacteria are there at some time t
  • given p(t0 ) = 41

?

  • More general: find p(t) for some range a<t<b
slide-6
SLIDE 6

Differential Equations

 Simple growth of bacteria model:

 r – rate of growth  p – population size

dp(t) dt =C p(t)

This is the derivative of p!

slide-7
SLIDE 7

Differential Equations

 Simple growth of bacteria model:

 r – rate of growth  p – population size

dp(t) dt =C p(t)

This is the derivative of p! Contrast this with in difference equations → now the change also needs to be a continuous function of time!

Δ Pt−1

slide-8
SLIDE 8

Differential Equations

 Simple growth of bacteria model:

 r – rate of growth  p – population size

dp(t) dt =C p(t)

Also:

˙ p(t)=C p(t) ˙ p=C p p'(t)=C p(t)

slide-9
SLIDE 9

Differential Equations

 Simple growth of bacteria model:

 r – rate of growth  p – population size

 Different types

 ordinary (ODEs) : all derivatives w.r.t. 1 'independent variable'

(vs. 'partial DE' with multiple variables)

 Order of a DE: maximum order of differentiation.

dp(t) dt =C p(t) p'(t)=C p(t)

slide-10
SLIDE 10

Problem

 Given an ODE  find a function y(t) that satisfies it.

y'(t)=f (t , y(t)), ∀t∈I

some time interval

slide-11
SLIDE 11

Problem

 Given an ODE  find a function y(t) that satisfies it.

y'(t)=f (t , y(t)), ∀t∈I f (t , y(t))=C y(t)

slide-12
SLIDE 12

Problem

 Given an ODE  find a function y(t) that satisfies it.  But: there are

infinitely many solutions!

y'(t)=f (t , y(t)), ∀t∈I f (t , y(t))=C y(t)

t y(t)

slide-13
SLIDE 13

Direction Fields

y'(t)=f (t , y(t)), ∀t∈I

t y(t) 1

f (t , y(t))=1 y(t)

 Given an ODE  Many functions satisfy it...  Let's plot the derivatives...

f (t , y(t))=C y(t)

?

slide-14
SLIDE 14

Direction Fields

y'(t)=f (t , y(t)), ∀t∈I

t y(t) 1

f (t , y(t))=1 y(t)

 Given an ODE  Many functions satisfy it...  Let's plot the derivatives...

f (t , y(t))=C y(t)

slide-15
SLIDE 15

Direction Fields

y'(t)=f (t , y(t)), ∀t∈I

t y(t) 1

f (t , y(t))=1 y(t)

 Given an ODE  Many functions satisfy it...  Let's plot the derivatives...

f (t , y(t))=C y(t)

slide-16
SLIDE 16

Direction Fields

y'(t)=f (t , y(t)), ∀t∈I

t y(t) 1

f (t , y(t))=1 y(t)

 Given an ODE  Many functions satisfy it...  Let's plot the derivatives...

f (t , y(t))=C y(t)

slide-17
SLIDE 17

Direction Fields

y'(t)=f (t , y(t)), ∀t∈I

t y(t) 1

f (t , y(t))=1 y(t)

 Given an ODE  Many functions satisfy it...  Let's plot the derivatives...

f (t , y(t))=C y(t)

slide-18
SLIDE 18

Direction Fields

y'(t)=f (t , y(t)), ∀t∈I

t y(t) 1

f (t , y(t))=1 y(t)

 Given an ODE  Many functions satisfy it...  Let's plot the derivatives...

f (t , y(t))=C y(t)

slide-19
SLIDE 19

Initial Value problem

 Given an ODE  find a function y(t) that satisfies it.  Initial Value Problem

(also: 'Cauchy Problem')

 specifies y(t0)

→ unique solution

y'(t)=f (t , y(t)), ∀t∈I

t y(t) y(t 0)=17

slide-20
SLIDE 20

Initial Value problem

 Initial value problem:  find a function y(t) that satisfies it

y '(t)=f (t , y(t)), ∀t∈I

t y(t)

y(t 0)=17

y(t0)=y0

slide-21
SLIDE 21

Initial Value problem

 Initial value problem:  find a function y(t) that satisfies it

y '(t)=f (t , y(t)), ∀t∈I

t y(t)

y(t 0)=17

y(t0)=y0

However...

  • closed-form solutions y(t) only available for very special cases.

→ Need for numerical solutions! Approach

  • Discretization: divide interval I in short steps of length h
  • At each node tn compute
  • Numerical solution:

un≈ y(tn) {u0,u1,...,uN}

slide-22
SLIDE 22

Initial Value problem

 Initial value problem:  find a function y(t) that satisfies it

y '(t)=f (t , y(t)), ∀t∈I

t y(t)

y(t 0)=17

y(t0)=y0

However...

  • closed-form solutions y(t) only available for very special cases.

→ Need for numerical solutions! Approach

  • Discretization: divide interval I in short steps of length h
  • At each node tn compute
  • Numerical solution:

un≈ y(tn) {u0,u1,...,uN}

Effectively we perform a simulation!

slide-23
SLIDE 23

Forward Euler Method

 The forward Euler method

 just perform the 'simulation'  shorthand

f n=f (tn,un) un+1=un+hf n

slide-24
SLIDE 24

Forward Euler Method

 The forward Euler method

 just perform the 'simulation'  shorthand

f n=f (tn,un) un+1=un+hf n

Example t = (0,19) h = 1 p(0) = 12740 r(p) = 0.1 * p

u0=12740

slide-25
SLIDE 25

Forward Euler Method

 The forward Euler method

 just perform the 'simulation'  shorthand

f n=f (tn,un) un+1=un+hf n

Example t = (0,19) h = 1 p(0) = 12740 r(p) = 0.1 * p

u0=12740 u1=u0+h∗r(u0)=12740+1∗1274.0=14014

slide-26
SLIDE 26

Forward Euler Method

 The forward Euler method

 just perform the 'simulation'  shorthand

f n=f (tn,un) un+1=un+hf n

Example t = (0,19) h = 1 p(0) = 12740 r(p) = 0.1 * p

u0=12740 u2=u1+h∗r(u1)=14014+1∗1401.4=15415.40 u1=u0+h∗r(u0)=12740+1∗1274.0=14014

slide-27
SLIDE 27

Forward Euler Method – Errors

 Errors...

t y(t)

slide-28
SLIDE 28

Forward Euler Method – Errors

 Errors...

t y(t) t y(t)

slide-29
SLIDE 29

Computational Issues

 How accurate is this?  Does it 'converge' ?  What is the order p of convergence?

slide-30
SLIDE 30

Computational Issues

 How accurate is this?  Does it 'converge' ?  What is the order p of convergence?

Can we deriver an expression for the error? Do we have if h → 0, does error → 0 ?

∣err∣<C(h)=O(h

p)

slide-31
SLIDE 31

Computational Issues

 How accurate is this?  Does it 'converge' ?  What is the order p of convergence?

Can we deriver an expression for the error? Do we have if h → 0, does error → 0 ?

∣err∣<C(h)=O(h

p)

  • forward Euler method converges with order 1
  • roughly: “h twice as small → error twice as small”
  • the book discusses many methods with higher order.
  • Matlab implements many:
  • de23, ode45, ode113, ode15s, ode23s, ode23t,
  • de23tb
  • “doc ode23”
slide-32
SLIDE 32

Computational Issues

 Do they matter?

 yes...

what to use? Matlab's doc: “ode45 should be first you try”