Finite Difference
Finite Difference
APPLIED NUMERICAL
METHOD
PROJECT 3:
FINITE DIFFERENCE METHOD
FACULTY OF MECHANICAL ENGINEERING
UNIVERSITI TEKNOLOGI MALAYSIA (UTM)
BY
ALEX ISKANDAR BIN JASRIZAL
930626-01-6073
B14KM0001
Introduction
Many option contract values can be obtained by solving of partial differential
equations with certain initial and boundary conditions. The finite difference approach is one
of the premier mathematical tools employed to solve partial differential equations. The finite
difference approach was pioneered for valuing derivative securities by Swartz [1977] and
Brennan and Swartz [1978] and has been extended by Courtadon[1988].
There are two implementations for the finite difference method: explicit method and
implicit method. The explicit finite difference method calculates the value of a derivative
security at time t +t as a function of values at time t. The calculations develop recursively
from time 0 to time T.
The implicit finite difference method calculates the value of a derivative security at
time t as a function of values at time t + t. The implicit method requires solving systems of
linear equations to develop calculations from time t to time t+t. To compare stability of
finite difference methods we classify finite difference method as unstable, conditionally
stable or unconditionally stable2.
Unstable finite difference method calculates large change in option value for small
change of the initial conditions (i.e. spot price). It accumulates large calculation error.
Unstable finite difference method does not converge to the solution of the partial differential
equation.
Conditionally stable finite difference method calculates small change in the option
value for a small change of the initial conditions. It converges to the solution of the partial
differential equation, and calculation error decreases when number of time and price
partitions increase.
Here, the function f(x) is graphically shown, with the function evaluated at 3 consecutive
variable x:
fi+1 at x = xi+1
fi at x = xi, and
fi-1 at x = xi-1
The finite differences method uses the differential form of the equations. For the FD these
equations are approximated by a Taylor expansion. Depending on the accuracy requirements,
higher order terms are neglected. Starting from the discretization in Fig.1, where point two
lies between points 1 and 3, and assuming that all the points are separated by the same
distance, we can apply the following Taylor expansion:
1 2 x
2
1
x 2
2
2
x
....
2
3 2 x
1 2 2
x
2
2
x
....
2
Truncating after the third term and subtracting/adding Eq. (Error: Reference source not
found-1) from/to Eq. (Error: Reference source not found-2), we get:
3 1
2 x
and
2
x
1 3 2 2
x 2
1 3 2 2
x 2
f 2
Since the Taylor series was expanded only up to the quadratic terms, one can infer that the
estimate of the error arising from the space discretization to be on the order of O(x 2), or, in
other words, the accuracy of the applied discretization is second order in space. Generalizing
the formulation for a generic node i, Eq. (Error: Reference source not found-Error: Reference
source not found) is written as:
i 1 i 1 2 i
x 2
f i
for i = 2,...n-1
This relation can be formulated for all nodes of the computational domain. By doing so, we
obtain a matrix, which has a tridiagonal form, i.e. it has nonzero elements only in the main
diagonal, the first diagonal below this, and the first diagonal above the main diagonal:
0
0
0
0
2 1 0
1 2 1 0
.
0
0
.
0
0 1 2 1 .
1
A
0
0 1 2 1 .
0
2
x
0
.
. 1 2 1 0
0
.
. 1 2 1
0
0
0
0
0
0 1 2
(Error: Reference source not found-7)
If we denote the solution vector as xT = [1, 2, 3, ...n] and the right-hand-side of the
equation as bT = [f1, f2, f3, ... fn], we obtain a matrix equation:
A x b
fr i = 2,...n-1
The example showed that the finite differences method transforms the PDG into a system of
algebraic equations. In addition, it can be shown that the approximate solution converges
towards the real one, when the number of discretization points goes to infinity.
Program stops when iteration number in plot does not change or can be closed anytime by
just closing the plot window. On normal completion, the program plots the electric field in a
quiver plot.
Matlab Code
clear all;
clc;
xdim=30;
ydim=30;
i=1:1:xdim+1;
V_now(i,ydim+1)=45*((i-1)/xdim).*(1-((i-1)/xdim));
iter=0;
error=max(max(abs(V_now-V_prev)));
%Iteration counter
while(error>0.01)
iter=iter+1;
%Iteration loop
%Run this until convergence
%Iteration counter increment
%Updating present iteration
using 4 point Central difference
form of Laplace equation
obtained using Finite Difference
method
for i=2:1:xdim
for j=2:1:ydim
V_now(i,j)=(V_now(i-1,j)+V_now(i+1,j)+V_now(i,j1)+V_now(i,j+1))/4;
end
end
error=max(max(abs(V_now-V_prev)));
%Calculate the maximum error
between previous and current
iteration at all points
V_prev=V_now;
%Updating previous iteration
matrix to the last iteration
performed
end
figure;
[ex,ey]=gradient(V_now);
quiver(-ex,-ey);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% END OF PROGRAM
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Result
Conclusion
Conceptually the most simple of the numerical methods and can be learned quite
quickly.
Depending on the physical problem FD methods are conditionally stable (relation
be summed up quite simply: the finite difference method is the quick and dirty method for
solving simple differential equations. Finite difference (FD) methods are intuitive and easy to
implement for simple problems. However, they quickly become unwieldy if you need to start
adding any sort of complexity like moving boundaries or an unstructured grid. There are
ways to make finite differences work, but hardly anybody uses them for modelling
complex
phenomena
because
it's
just
too
hard
to
get
them
to
work.