SlideShare a Scribd company logo
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.

More Related Content

PDF
Algorithm chapter 2
PDF
Time-Series Analysis on Multiperiodic Conditional Correlation by Sparse Covar...
PPTX
Chapter one
PDF
Presentation on stochastic control problem with financial applications (Merto...
PPT
Analysis of Algorithum
PPT
Fundamentals of the Analysis of Algorithm Efficiency
PDF
Ch24 efficient algorithms
Algorithm chapter 2
Time-Series Analysis on Multiperiodic Conditional Correlation by Sparse Covar...
Chapter one
Presentation on stochastic control problem with financial applications (Merto...
Analysis of Algorithum
Fundamentals of the Analysis of Algorithm Efficiency
Ch24 efficient algorithms

What's hot (19)

PPT
Unit 3-Greedy Method
PPTX
Mathematical Analysis of Recursive Algorithm.
PPT
Design and Analysis of Algorithms
PPTX
Integer Linear Programming
PPT
PDF
Integer programming
PPTX
Analysis of algorithm
PPTX
Online Algorithms - An Introduction
PPT
Data Structures and Algorithm Analysis
PPTX
Global optimization
PDF
Daa notes 2
PPTX
Divide and Conquer - Part 1
PDF
Anlysis and design of algorithms part 1
PDF
PPT
Design and analysis of Algorithm By Dr. B. J. Mohite
PDF
Boyd 4.6, 4.7
PPTX
Algorithm analysis (All in one)
PPT
CS8461 - Design and Analysis of Algorithms
Unit 3-Greedy Method
Mathematical Analysis of Recursive Algorithm.
Design and Analysis of Algorithms
Integer Linear Programming
Integer programming
Analysis of algorithm
Online Algorithms - An Introduction
Data Structures and Algorithm Analysis
Global optimization
Daa notes 2
Divide and Conquer - Part 1
Anlysis and design of algorithms part 1
Design and analysis of Algorithm By Dr. B. J. Mohite
Boyd 4.6, 4.7
Algorithm analysis (All in one)
CS8461 - Design and Analysis of Algorithms
Ad

Similar to First part of my NYU Tandon course "Numerical and Simulation Techniques in Finance" (20)

PDF
Mit18 330 s12_chapter4
PDF
PDF
James_F_Epperson_An_Introduction_to_Numerical_Methods_and_Analysis.pdf
PDF
Numerical Study of Some Iterative Methods for Solving Nonlinear Equations
PDF
A Derivative Free High Ordered Hybrid Equation Solver
PDF
A derivative free high ordered hybrid equation solver
PDF
numericalmethods.pdf
PDF
A Comparison Of Iterative Methods For The Solution Of Non-Linear Systems Of E...
PDF
Applications Of MATLAB Ordinary Differential Equations (ODE
DOC
NUMERICAL METHODS MULTIPLE CHOICE QUESTIONS
PDF
Numerical Study of Some Iterative Methods for Solving Nonlinear Equation.pdf
DOCX
Numerical Analysis and Computer Applications
DOCX
Matlab lab manual
PDF
Lecture6.handout
PDF
A DERIVATIVE FREE HIGH ORDERED HYBRID EQUATION SOLVER
PDF
S3-3.pdf
PPT
Ch08 1
PDF
New Two-Step Method with Fifth-Order Convergence for Solving Nonlinear Equations
DOCX
CALIFORNIA STATE UNIVERSITY, NORTHRIDGEMECHANICAL ENGINEERIN.docx
Mit18 330 s12_chapter4
James_F_Epperson_An_Introduction_to_Numerical_Methods_and_Analysis.pdf
Numerical Study of Some Iterative Methods for Solving Nonlinear Equations
A Derivative Free High Ordered Hybrid Equation Solver
A derivative free high ordered hybrid equation solver
numericalmethods.pdf
A Comparison Of Iterative Methods For The Solution Of Non-Linear Systems Of E...
Applications Of MATLAB Ordinary Differential Equations (ODE
NUMERICAL METHODS MULTIPLE CHOICE QUESTIONS
Numerical Study of Some Iterative Methods for Solving Nonlinear Equation.pdf
Numerical Analysis and Computer Applications
Matlab lab manual
Lecture6.handout
A DERIVATIVE FREE HIGH ORDERED HYBRID EQUATION SOLVER
S3-3.pdf
Ch08 1
New Two-Step Method with Fifth-Order Convergence for Solving Nonlinear Equations
CALIFORNIA STATE UNIVERSITY, NORTHRIDGEMECHANICAL ENGINEERIN.docx
Ad

Recently uploaded (20)

PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Computing-Curriculum for Schools in Ghana
PDF
RMMM.pdf make it easy to upload and study
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Complications of Minimal Access Surgery at WLH
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Pharma ospi slides which help in ospi learning
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Cell Structure & Organelles in detailed.
PDF
Insiders guide to clinical Medicine.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Anesthesia in Laparoscopic Surgery in India
Computing-Curriculum for Schools in Ghana
RMMM.pdf make it easy to upload and study
Module 4: Burden of Disease Tutorial Slides S2 2025
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Complications of Minimal Access Surgery at WLH
O5-L3 Freight Transport Ops (International) V1.pdf
Renaissance Architecture: A Journey from Faith to Humanism
VCE English Exam - Section C Student Revision Booklet
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Microbial diseases, their pathogenesis and prophylaxis
TR - Agricultural Crops Production NC III.pdf
Pharma ospi slides which help in ospi learning
PPH.pptx obstetrics and gynecology in nursing
Cell Structure & Organelles in detailed.
Insiders guide to clinical Medicine.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf

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

  • 1. 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.
  • 2. THE PURPOSE OF COMPUTING IS INSIGHT, NOT NUMBERS… --- R. W. Hamming Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 3. 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.
  • 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. 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.
  • 6. 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.
  • 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 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.
  • 10. “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.
  • 11. 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.
  • 12. FIRST PROBLEM Compute implied volatility of European call option (e.g. one dimensional root finding) Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 13. BISECTION METHOD LO HIMID If f(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 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.
  • 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 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.
  • 19. 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.
  • 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 numerical solution to an ordinary differential equation Copyright 2018 Weinberger Post-Quantitative, Inc.
  • 25. HOW DO WE KNOW 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 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.
  • 27. 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.
  • 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 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.
  • 30. 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)
  • 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 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       
  • 35. 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    
  • 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 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.
  • 39. 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.
  • 40. 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.
  • 41. 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.
  • 42. 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.
  • 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 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.
  • 45. 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.
  • 46. 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.