Numerical & Simulation
Techniques in Finance
FRE 6251
Chapter I
Edward D. Weinberger, Ph.D, F.R.M.
Adjunct Assoc. Professor
NYU Tandon School of Engineering
edw@wpq-inc.com
Copyright 2018 Weinberger
Post-Quantitative, Inc.
THE PURPOSE OF
COMPUTING IS INSIGHT,
NOT NUMBERS…
--- R. W. Hamming
Copyright 2018 Weinberger
Post-Quantitative, Inc.
COURSE OBJECTIVES
•To familiarize students with
•what makes a “good” method
•some important methods
•EXCEL/VBA
•To teach the “informed use” of
numerical methods in packages
Copyright 2018 Weinberger
Post-Quantitative, Inc.
COURSE
ORGANIZATION
Grade based on
• Two algorithm implementations (50%
each)
• Required texts:
• Numerical Methods in C(++) by Frank Press, et. al.
(available free at http://www.nrbook.com/a/bookcpdf.php
• Options, Futures and Other Derivatives
`
Copyright 2018 Weinberger
Post-Quantitative, Inc.
TOPIC SCHEDULE
(Approximate!)
I. Root finding in 1 or more dim
II. Ordinary Differential Eqns.
(ODE’s)
III. Partial Differential Eqns. (PDE’s)
IV. Numerical Integration
V. Interpolation
VI. A Survey of Optimization
Copyright 2018 Weinberger
Post-Quantitative, Inc.
OUTLINE
Chapter I
• VBA survey for programmers
• “Machine numbers”
• 1 dim root finding methods
• bisection
• secant method
• Newton’s method
• Newton’s method in >1 dim
• ODE solvers
Copyright 2018 Weinberger
Post-Quantitative, Inc.
VBA for Programmers
• VBA NOT “industrial strength”,
unlike C++ (VBA not really OO)
• Visual Basic for Applications (VBA)
is macro language for all MS Office
• Built-in references to relevant
“objects”
• EXCEL/VBA has “Range”, “Cell”,
“Worksheet” objects (see HELP)
Copyright 2018 Weinberger
Post-Quantitative, Inc.
More VBA for
Programmers
• EXCEL functions accessible in VBA,
Applications.WorksheetFunction.min()
• “Immediate” window
• Integrated development environment
• “Record Macro” to get hints
Copyright 2018 Weinberger
Post-Quantitative, Inc.
“MACHINE NUMBERS” AS
SUBSETS OF R
• Integers represented in binary using 1
(“char”), 2 (“short”), 4 (“float”), or 8
(“long”) bytes
• Floating point numbers represented in
4 (“float”) or 8 (“double”) bytes
• Implications:
•Integer/floating point overflow
•Tests like (x == 0.25) may not work
•Cancellation (see example)
Copyright 2018 Weinberger
Post-Quantitative, Inc.
“MACHINE EPSILON”
• Smallest absolute value of non-zero
mantissa representable on machine
• Different for different machines and
different applications
• For EXCEL/VBA on my machine:
•1.19 x 10-7 for single precision
•9.31 x 10-10 for double precision
Copyright 2018 Weinberger
Post-Quantitative, Inc.
RELATIVE SPEED
ESTIMATION
• Want machine independent estimates
• Addition/Subtraction/branching fast
• Multiplication/Division slow
• Function calls slowest
• Use O(N ) notation
Copyright 2018 Weinberger
Post-Quantitative, Inc.
FIRST PROBLEM
Compute implied volatility of
European call option (e.g. one
dimensional root finding)
Copyright 2018 Weinberger
Post-Quantitative, Inc.
BISECTION METHOD
LO HIMID
If f(MID) ≥ 0
HI = MID
Else
LO = MID
Copyright 2018 Weinberger
Post-Quantitative, Inc.
SECANT METHOD
xn-2 xn-1xn
     
1
21
21
11



 








nn
nn
nnn
xx
xfxf
xfxx
Copyright 2018 Weinberger
Post-Quantitative, Inc.
NEWTON’S METHOD
xn-1 xn
xn-2
 
 










1
1
1
n
n
nn
xf
xf
xx
Copyright 2018 Weinberger
Post-Quantitative, Inc.
ROOT FINDER TRADE-
OFFS
METHOD ADVANTAGE DISADVANTAGE
Bisection Always converges Very slow (lots of fct evaluations)
Secant Fast (few fct evaluations)
Need not code separate
derivative
calculation
Can get lost
Newton Fastest Need code for derivative calculation
Can get lost
Brent Almost as fast as secant, but
doesn’t get lost.
Complex!
Copyright 2018 Weinberger
Post-Quantitative, Inc.
Desiderata
“Read user’s mind” regarding
what user wants, finding a
solution
• correctly and reliably (lever
expert knowledge, e.g. Brent)
• quickly and cheaply
• in a user friendly way,
consistent with how users think
Copyright 2018 Weinberger
Post-Quantitative, Inc.
THE STATE OF THE ART
• Numerical Libraries (Numerical
Recipes)
• Batch processing for numerical
calculation (GAMS)
• Interactive processing for numerical
calculation (MatLab)
• Symbolic calculation (Macsyma,
Maple, Mathematica, esp integrator)
Copyright 2018 Weinberger
Post-Quantitative, Inc.
THE STATE OF THE ART
• Numerical Integration of Block Diagrams
(SimuLink)
See also Wikipedia entry
http://en.wikipedia.org/wiki/
Comparison_of_numerical_
analysis_software
Copyright 2018 Weinberger
Post-Quantitative, Inc.
Types of Calculations
• Statistical Analysis
EXCEL, SAS, S+, R, GAMS, MatLab/Octave
• Matrix Manipulation
EXCEL, MatLab/Octave
• Optimization
EXCEL, MatLab/Octave, GAMS
• Differential Equations (ODE, PDE)
MatLab/OctaveCopyright 2018 Weinberger
Post-Quantitative, Inc.
Types of Calculations
• Special Functions
EXCEL (Normal Dist.), MatLab/Octave
• Fast Fourier Transform (FFT)
EXCEL, MatLab/Octave
• Root Finding
EXCEL (Solver), MatLab/Octave
• Numerical Integration
MatLab/OctaveCopyright 2018 Weinberger
Post-Quantitative, Inc.
NEWTON’S METHOD IN >1
DIMENSION
GOAL: Solve f (x) = 0, for “smooth” f by
iteration: Given xn, improve it to xn+1 = xn + δ
f (xn + δ) = f (xn) + J δ + O (|| δ ||2),
where
J = [∂ fi / ∂ xj ]
Copyright 2018 Weinberger
Post-Quantitative, Inc.
NEWTON’S METHOD IN >1
DIMENSION (cont)
Using f (xn + δ) = 0
0 ≈ f (xn) + J δ
so
- J -1 f (x) ≈ δ
and
xn = xn-1 + δ
Copyright 2018 Weinberger
Post-Quantitative, Inc.
SECOND PROBLEM
Compute numerical solution to
an ordinary differential
equation
Copyright 2018 Weinberger
Post-Quantitative, Inc.
HOW DO WE KNOW A
SOLUTION EXISTS?
ODE with no real solution:
12
2






x
dt
dx
Copyright 2018 Weinberger
Post-Quantitative, Inc.
ODE’S IN STANDARD
FORM
Almost any ODE or system of ODE’s can be written
in the form
dx1/dt = f1(x1, x2 … xN , t)
dxN /dt = fN (x1, x2 … xN , t)
}dx(t) /dt = f (x, t)
Copyright 2018 Weinberger
Post-Quantitative, Inc.
PICARD EXISTENCE
THEOREM
THEOREM: The initial value problem
dx/dt = f (x,t)
with initial condition x(0) = x0 has a unique real solution in the
appropriate region if f satisfies a “Lipschitz condition”, i.e.
|| f (y, t) - f (x, t) || ≤ const X || y - x ||
for all relevant t.
Copyright 2018 Weinberger
Post-Quantitative, Inc.
EULER’S METHOD
By definition,
     
        hohttxftxhtx
h
txhtx
dt
tdx
h





,
lim
0
Copyright 2018 Weinberger
Post-Quantitative, Inc.
xn+1 = xn+ h f (xn , tn)
EXAMPLE: SIMPLE
HARMONIC MOTION
d x1/dt = x2
d 2 x/dt2 = -4π2 k 2x
d x2/dt = -4π2 k2 x1
x1(t + h) = x1 (t) + x2(t) h
x2(t + h) = x2 (t) – 4π2 k 2 x1(t) h
Copyright 2018 Weinberger
Post-Quantitative, Inc.
EULER’S IMPLICIT
METHOD
In one dimension, use
x(t + h) = x(t) + f (x (t + h), t + h) h.
so
x(t + h) - f (x (t + h), t + h) h = x(t).
Copyright 2018 Weinberger
Post-Quantitative, Inc.
xn+1 = xn+ h f (xn+1 , tn+1)
EXAMPLE: SIMPLE
HARMONIC MOTION
x1(t + h) – x2(t + h) h = x1 (t)
x2(t + h) + 4π2 k2 x1(t + h) h = x2 (t)
x1(t + h) = [x1(t) + x2(t) h] / [1 + 4π2 k2 h]
x2(t + h) = [- 4π2k2h x1(t) + x2(t)] / [1 + 4π2k2h]
Copyright 2018 Weinberger
Post-Quantitative, Inc.
STABILITY ANALYSIS:
EULER’S (EXPLICIT) METHOD
Consider: dx/dt = - ax, a > 0
x(t + h) = x(t)[1 - ah]
x(t + nh) = x(t)[1 - ah]n
so we must have |1 – ah| < 1, or h < 2/a for
convergence
Copyright 2018 Weinberger
Post-Quantitative, Inc.
STABILITY ANALYSIS:
EULER’S (IMPLICIT) METHOD
Consider: dx/dt = - ax
x(t + h) = x(t) - ah x(t + h)
x(t + h) = x(t) /[1 + ah]
x(t + nh) = x(t) /[1 + ah]n
Much better convergence properties!!
Copyright 2018 Weinberger
Post-Quantitative, Inc.
MIDPOINT METHOD
For any function g(t), Taylor series expansion is
Copyright 2018 Weinberger
Post-Quantitative, Inc.
     
     
     2
32
2
2
2
1
32
2
2
2
1
2
hO
dt
dg
h
htghtg
hOh
dt
gd
h
dt
dg
tghtg
hOh
dt
gd
h
dt
dg
tghtg
n
nn
nn
tt
nn
ttttnn
ttttnn







MIDPOINT METHOD
In the present case
Copyright 2018 Weinberger
Post-Quantitative, Inc.
   
 
    
        
        .,2/
But.2/,2/
so,2/,2/
2/2
2
2
1
3
2
hOhttxftxhtx
hOhhthtxftxhtx
hOhthtxf
h
txhtx




MIDPOINT METHOD
HENCE
xn +1 = xn + h f (xn + k1/2, tn + h/2) + O(h 3)
k1 = h f (xn , tn)
if stepsize = h
OR
xn +1 = xn -1 + 2h f (xn, tn) + O(h 3)
if stepsize = 2h
Copyright 2018 Weinberger
Post-Quantitative, Inc.
MIDPOINT METHOD
xn xn+ h
xn+ h/2
f(xn+ h/2, yn)
Copyright 2018 Weinberger
Post-Quantitative, Inc.
CONSISTENCY: NECESSARY
BUT NOT SUFFICIENT
A method is consistent if its order of
accuracy is at least 1, i.e. truncation error
is O(h2)
Explicit Euler, Implicit Euler, and the
Midpoint method are all consistent.
Copyright 2018 Weinberger
Post-Quantitative, Inc.
WHAT WE REALLY WANT IS
CONVERGENCE
A method is convergent if
Max | xj – x(tj) | 0
as h 0
Copyright 2018 Weinberger
Post-Quantitative, Inc.
MULTI-STEP METHODS
Why not generalize midpoint method to
xn+1 = a0 xn + a1 xn-1 + a2 xn-2 + …
+ h [b0 f(xn , tn) + b1 f(xn-1 , tn-1) + …]
as long as formula is consistent?
Copyright 2018 Weinberger
Post-Quantitative, Inc.
MULTI-STEP METHODS
Answer: Not always stable
xn+1 = -4 xn + 5xn-1 + h [4 f(xn , tn) + 2 f(xn-1 , tn-1)]
is unstable for any h!
Copyright 2018 Weinberger
Post-Quantitative, Inc.
DAHLQUIST EQIVALENCE
THEOREM
Theorem: A multi-step method for solving an ODE
is consistent and stable if and only if it is convergent
(stay tuned for more on this)
Copyright 2018 Weinberger
Post-Quantitative, Inc.
RUNGE KUTTA
(4th Order)
k1 = h f (xn , yn)
k2 = h f (xn + h/2, yn + k1/2)
k3 = h f (xn + h/2, yn + k2/2)
k4 = h f (xn + h, yn + k3)
yn +1 = yn + k1/ 6+ k2/ 3+ k3/ 3+ k4/ 6 + O(h5)
Copyright 2018 Weinberger
Post-Quantitative, Inc.
RUNGE KUTTA
Adaptive Step Size
x = True solution
xh = RK solution with step size h
x2h = RK solution with step size 2h
x(t + 2h) = xh(t + 2h) + 2h 5φ + O(h6)
x(t + 2h) = x2h(t + 2h) + (2h) 5φ + O(h6)
Copyright 2018 Weinberger
Post-Quantitative, Inc.
RUNGE KUTTA
Adaptive Step Size
Δ =x2h(t + 2h) - xh(t + 2h) = 30h 5φ + O(h6)
If |Δ| > Tol1 then
replace h with h/2
else if |Δ| < Tol2 then
replace h with 2h
end if
Copyright 2018 Weinberger
Post-Quantitative, Inc.
SUMMARY
Chapter I
• VBA highlights
• “Machine numbers”
• 1 dim root finding methods
• bisection
• secant method
• Newton’s method
• Newton’s method in >1 dim
• ODE solvers
Copyright 2018 Weinberger
Post-Quantitative, Inc.

First part of my NYU Tandon course "Numerical and Simulation Techniques in Finance"

  • 1.
    Numerical & Simulation Techniquesin Finance FRE 6251 Chapter I Edward D. Weinberger, Ph.D, F.R.M. Adjunct Assoc. Professor NYU Tandon School of Engineering edw@wpq-inc.com Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 2.
    THE PURPOSE OF COMPUTINGIS INSIGHT, NOT NUMBERS… --- R. W. Hamming Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 3.
    COURSE OBJECTIVES •To familiarizestudents with •what makes a “good” method •some important methods •EXCEL/VBA •To teach the “informed use” of numerical methods in packages Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 4.
    COURSE ORGANIZATION Grade based on •Two algorithm implementations (50% each) • Required texts: • Numerical Methods in C(++) by Frank Press, et. al. (available free at http://www.nrbook.com/a/bookcpdf.php • Options, Futures and Other Derivatives ` Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 5.
    TOPIC SCHEDULE (Approximate!) I. Rootfinding in 1 or more dim II. Ordinary Differential Eqns. (ODE’s) III. Partial Differential Eqns. (PDE’s) IV. Numerical Integration V. Interpolation VI. A Survey of Optimization Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 6.
    OUTLINE Chapter I • VBAsurvey for programmers • “Machine numbers” • 1 dim root finding methods • bisection • secant method • Newton’s method • Newton’s method in >1 dim • ODE solvers Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 7.
    VBA for Programmers •VBA NOT “industrial strength”, unlike C++ (VBA not really OO) • Visual Basic for Applications (VBA) is macro language for all MS Office • Built-in references to relevant “objects” • EXCEL/VBA has “Range”, “Cell”, “Worksheet” objects (see HELP) Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 8.
    More VBA for Programmers •EXCEL functions accessible in VBA, Applications.WorksheetFunction.min() • “Immediate” window • Integrated development environment • “Record Macro” to get hints Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 9.
    “MACHINE NUMBERS” AS SUBSETSOF R • Integers represented in binary using 1 (“char”), 2 (“short”), 4 (“float”), or 8 (“long”) bytes • Floating point numbers represented in 4 (“float”) or 8 (“double”) bytes • Implications: •Integer/floating point overflow •Tests like (x == 0.25) may not work •Cancellation (see example) Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 10.
    “MACHINE EPSILON” • Smallestabsolute value of non-zero mantissa representable on machine • Different for different machines and different applications • For EXCEL/VBA on my machine: •1.19 x 10-7 for single precision •9.31 x 10-10 for double precision Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 11.
    RELATIVE SPEED ESTIMATION • Wantmachine independent estimates • Addition/Subtraction/branching fast • Multiplication/Division slow • Function calls slowest • Use O(N ) notation Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 12.
    FIRST PROBLEM Compute impliedvolatility of European call option (e.g. one dimensional root finding) Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 13.
    BISECTION METHOD LO HIMID Iff(MID) ≥ 0 HI = MID Else LO = MID Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 14.
    SECANT METHOD xn-2 xn-1xn      1 21 21 11              nn nn nnn xx xfxf xfxx Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 15.
    NEWTON’S METHOD xn-1 xn xn-2              1 1 1 n n nn xf xf xx Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 16.
    ROOT FINDER TRADE- OFFS METHODADVANTAGE DISADVANTAGE Bisection Always converges Very slow (lots of fct evaluations) Secant Fast (few fct evaluations) Need not code separate derivative calculation Can get lost Newton Fastest Need code for derivative calculation Can get lost Brent Almost as fast as secant, but doesn’t get lost. Complex! Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 17.
    Desiderata “Read user’s mind”regarding what user wants, finding a solution • correctly and reliably (lever expert knowledge, e.g. Brent) • quickly and cheaply • in a user friendly way, consistent with how users think Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 18.
    THE STATE OFTHE ART • Numerical Libraries (Numerical Recipes) • Batch processing for numerical calculation (GAMS) • Interactive processing for numerical calculation (MatLab) • Symbolic calculation (Macsyma, Maple, Mathematica, esp integrator) Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 19.
    THE STATE OFTHE ART • Numerical Integration of Block Diagrams (SimuLink) See also Wikipedia entry http://en.wikipedia.org/wiki/ Comparison_of_numerical_ analysis_software Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 20.
    Types of Calculations •Statistical Analysis EXCEL, SAS, S+, R, GAMS, MatLab/Octave • Matrix Manipulation EXCEL, MatLab/Octave • Optimization EXCEL, MatLab/Octave, GAMS • Differential Equations (ODE, PDE) MatLab/OctaveCopyright 2018 Weinberger Post-Quantitative, Inc.
  • 21.
    Types of Calculations •Special Functions EXCEL (Normal Dist.), MatLab/Octave • Fast Fourier Transform (FFT) EXCEL, MatLab/Octave • Root Finding EXCEL (Solver), MatLab/Octave • Numerical Integration MatLab/OctaveCopyright 2018 Weinberger Post-Quantitative, Inc.
  • 22.
    NEWTON’S METHOD IN>1 DIMENSION GOAL: Solve f (x) = 0, for “smooth” f by iteration: Given xn, improve it to xn+1 = xn + δ f (xn + δ) = f (xn) + J δ + O (|| δ ||2), where J = [∂ fi / ∂ xj ] Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 23.
    NEWTON’S METHOD IN>1 DIMENSION (cont) Using f (xn + δ) = 0 0 ≈ f (xn) + J δ so - J -1 f (x) ≈ δ and xn = xn-1 + δ Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 24.
    SECOND PROBLEM Compute numericalsolution to an ordinary differential equation Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 25.
    HOW DO WEKNOW A SOLUTION EXISTS? ODE with no real solution: 12 2       x dt dx Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 26.
    ODE’S IN STANDARD FORM Almostany ODE or system of ODE’s can be written in the form dx1/dt = f1(x1, x2 … xN , t) dxN /dt = fN (x1, x2 … xN , t) }dx(t) /dt = f (x, t) Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 27.
    PICARD EXISTENCE THEOREM THEOREM: Theinitial value problem dx/dt = f (x,t) with initial condition x(0) = x0 has a unique real solution in the appropriate region if f satisfies a “Lipschitz condition”, i.e. || f (y, t) - f (x, t) || ≤ const X || y - x || for all relevant t. Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 28.
    EULER’S METHOD By definition,              hohttxftxhtx h txhtx dt tdx h      , lim 0 Copyright 2018 Weinberger Post-Quantitative, Inc. xn+1 = xn+ h f (xn , tn)
  • 29.
    EXAMPLE: SIMPLE HARMONIC MOTION dx1/dt = x2 d 2 x/dt2 = -4π2 k 2x d x2/dt = -4π2 k2 x1 x1(t + h) = x1 (t) + x2(t) h x2(t + h) = x2 (t) – 4π2 k 2 x1(t) h Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 30.
    EULER’S IMPLICIT METHOD In onedimension, use x(t + h) = x(t) + f (x (t + h), t + h) h. so x(t + h) - f (x (t + h), t + h) h = x(t). Copyright 2018 Weinberger Post-Quantitative, Inc. xn+1 = xn+ h f (xn+1 , tn+1)
  • 31.
    EXAMPLE: SIMPLE HARMONIC MOTION x1(t+ h) – x2(t + h) h = x1 (t) x2(t + h) + 4π2 k2 x1(t + h) h = x2 (t) x1(t + h) = [x1(t) + x2(t) h] / [1 + 4π2 k2 h] x2(t + h) = [- 4π2k2h x1(t) + x2(t)] / [1 + 4π2k2h] Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 32.
    STABILITY ANALYSIS: EULER’S (EXPLICIT)METHOD Consider: dx/dt = - ax, a > 0 x(t + h) = x(t)[1 - ah] x(t + nh) = x(t)[1 - ah]n so we must have |1 – ah| < 1, or h < 2/a for convergence Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 33.
    STABILITY ANALYSIS: EULER’S (IMPLICIT)METHOD Consider: dx/dt = - ax x(t + h) = x(t) - ah x(t + h) x(t + h) = x(t) /[1 + ah] x(t + nh) = x(t) /[1 + ah]n Much better convergence properties!! Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 34.
    MIDPOINT METHOD For anyfunction g(t), Taylor series expansion is Copyright 2018 Weinberger Post-Quantitative, Inc.                  2 32 2 2 2 1 32 2 2 2 1 2 hO dt dg h htghtg hOh dt gd h dt dg tghtg hOh dt gd h dt dg tghtg n nn nn tt nn ttttnn ttttnn       
  • 35.
    MIDPOINT METHOD In thepresent case Copyright 2018 Weinberger Post-Quantitative, Inc.                             .,2/ But.2/,2/ so,2/,2/ 2/2 2 2 1 3 2 hOhttxftxhtx hOhhthtxftxhtx hOhthtxf h txhtx    
  • 36.
    MIDPOINT METHOD HENCE xn +1= xn + h f (xn + k1/2, tn + h/2) + O(h 3) k1 = h f (xn , tn) if stepsize = h OR xn +1 = xn -1 + 2h f (xn, tn) + O(h 3) if stepsize = 2h Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 37.
    MIDPOINT METHOD xn xn+h xn+ h/2 f(xn+ h/2, yn) Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 38.
    CONSISTENCY: NECESSARY BUT NOTSUFFICIENT A method is consistent if its order of accuracy is at least 1, i.e. truncation error is O(h2) Explicit Euler, Implicit Euler, and the Midpoint method are all consistent. Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 39.
    WHAT WE REALLYWANT IS CONVERGENCE A method is convergent if Max | xj – x(tj) | 0 as h 0 Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 40.
    MULTI-STEP METHODS Why notgeneralize midpoint method to xn+1 = a0 xn + a1 xn-1 + a2 xn-2 + … + h [b0 f(xn , tn) + b1 f(xn-1 , tn-1) + …] as long as formula is consistent? Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 41.
    MULTI-STEP METHODS Answer: Notalways stable xn+1 = -4 xn + 5xn-1 + h [4 f(xn , tn) + 2 f(xn-1 , tn-1)] is unstable for any h! Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 42.
    DAHLQUIST EQIVALENCE THEOREM Theorem: Amulti-step method for solving an ODE is consistent and stable if and only if it is convergent (stay tuned for more on this) Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 43.
    RUNGE KUTTA (4th Order) k1= h f (xn , yn) k2 = h f (xn + h/2, yn + k1/2) k3 = h f (xn + h/2, yn + k2/2) k4 = h f (xn + h, yn + k3) yn +1 = yn + k1/ 6+ k2/ 3+ k3/ 3+ k4/ 6 + O(h5) Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 44.
    RUNGE KUTTA Adaptive StepSize x = True solution xh = RK solution with step size h x2h = RK solution with step size 2h x(t + 2h) = xh(t + 2h) + 2h 5φ + O(h6) x(t + 2h) = x2h(t + 2h) + (2h) 5φ + O(h6) Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 45.
    RUNGE KUTTA Adaptive StepSize Δ =x2h(t + 2h) - xh(t + 2h) = 30h 5φ + O(h6) If |Δ| > Tol1 then replace h with h/2 else if |Δ| < Tol2 then replace h with 2h end if Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 46.
    SUMMARY Chapter I • VBAhighlights • “Machine numbers” • 1 dim root finding methods • bisection • secant method • Newton’s method • Newton’s method in >1 dim • ODE solvers Copyright 2018 Weinberger Post-Quantitative, Inc.