CS计算机代考程序代写 matlab Errors, Convergence, Stiffness

Errors, Convergence, Stiffness
CS/SE 4X03
Ned Nedialkov McMaster University March 24, 2021

Outline
Local truncation error and order Local and global error Convergence
Stiffness
Stiff vs Nonstiff

Order Local and global error Convergence Stiffness Stiff vs Nonstiff Local truncation error and order
• Local truncation error is the amount by which the exact solution fails to satisfy the numerical method
• ForwardEuleryi+1 =yi+hf(ti,yi)
Using the exact solution y(t) in this formula
di = y(ti+1) − y(ti) − f(ti, y(ti)) = hy′′(ηi) h2
• Backward Euler di = −hy′′(ξi) 2
• A method is of order q, if q is the lowest positive integer such that for any sufficiently smooth exact solution y(t)
max|di| = O(hq) i
• Forward and backward Euler are of order q = 1
Copyright © 2021 N. Nedialkov. All rights reserved. 3/11

Order Local and global error Convergence Stiffness Stiff vs Nonstiff Local and global error
• Global error is
ei =y(ti)−yi, i=0,1,…,N,
where y(ti) is the exact solution at ti and yi is the computed
approximation
• Consider
u′ = f(t, u), u(ti−1) = yi−1 The local error is
li =u(ti)−yi
where u(ti) is the exact solution to u′ = f(t,u) with initial
condition ui at ti
Copyright © 2021 N. Nedialkov. All rights reserved. 4/11

Order Local and global error Convergence Stiffness Stiff vs Nonstiff Local vs global error
y
y 3 y4 2
y1
y5
y0
y6
y 7
y 8
y’=f(t,y), y(0)=y 0
u’=f(t,u), u(t )=y ii
computed approx local errors
y
y 3 y4 2
y1
y5
y0
y6
y 7
y 8
y’=f(t,y), y(0)=y 0
u’=f(t,u), u(t )=y ii
computed approx global errors
0 0.5 1 1.5 2 2.5 0 0.5 1 1.5 2 2.5 tt
Copyright © 2021 N. Nedialkov. All rights reserved. 5/11

Order
Local and global error Convergence Stiffness Stiff vs Nonstiff
• Numerical methods control the local error
• That is, select a stepsize such that the local error is within a
given tolerance
• Typically the global error is proportional to the tolerance
Copyright © 2021 N. Nedialkov. All rights reserved. 6/11

Order Local and global error Convergence Stiffness Stiff vs Nonstiff Convergence
• A methods is said to converge if the maximum global error goes to 0 as h → 0
• That is
maxei =max[y(ti)−yi]→0 ash→0 ii
Copyright © 2021 N. Nedialkov. All rights reserved.
7/11

Order Local and global error Convergence Stiffness Stiff vs Nonstiff Stiffness
• When the stepsize is restricted by stability rather than accuracy
• When an explicit solver takes very small steps
• Matlab: nonstiff solvers ode45, ode113,…
stiff solvers: ode15s, ode23s
Copyright © 2021 N. Nedialkov. All rights reserved. 8/11

Order Local and global error Convergence Stiffness Stiff vs Nonstiff Stiffness cont.
Van der Pol
y 1′ = y 2
y2′ =μ(1−y12)y2−y1
μ is a constant
y(0) = (2,0)T, t ∈ [0,2000]
Copyright © 2021 N. Nedialkov. All rights reserved. 9/11

Order Local and global error Convergence Stiffness Stiff vs Nonstiff
Stiff vs Nonstiff
ode15s on Van der Pol, μ = 1000: integrated in ≈ 0.2 seconds, 408 steps
2 1 0 -1 -2 -3
Solution of van der Pol Equation,
= 1000
1500 1000 500 0 -500 -1000 -1500
Solution of van der Pol Equation,
= 1000
100 80 60 40 20 0
0 500
1000 t
1500 2000
0 500
1000 Time t
Stepsize
1500 2000
0 500
1000 1500 Time t
2000
Stepsize Solution y
1
Solution y
2
Copyright © 2021 N. Nedialkov. All rights reserved.
10/11

Order Local and global error Convergence Stiffness Stiff vs Nonstiff Stiff vs Nonstiff
ode45 on Van der Pol, μ = 1000: integrated in ≈ 15 seconds, 4,624,409 steps
0.025 0.02 0.015 0.01 0.005 0
Stepsize
Stepsize
0 500
1000 1500 2000 t
Copyright © 2021 N. Nedialkov. All rights reserved.
11/11