Sei sulla pagina 1di 11

SKMM3023 :

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.

Finite Differenzes method


The principle of finite difference methods is close to the numerical schemes used to
solve ordinary differential equations. It consists in approximating the differential operator by
replacing the derivatives in the equation using differential quotients. The domain is
partitioned in space and in time and approximations of the solution are computed at the space
or time points. The error between the numerical solution and the exact solution is determined
by the error that is commited by going from a differential operator to a difference operator.
This error is called the discretization error or truncation error. The term truncation error
reflects the fact that a finite part of a Taylor series is used in the approximation.
Physically, a derivative represents the rate of change of a physical quantity represented by a
function with respect to the change of its variable(s):

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:

Fig.1: Discretization in the finite differences method.

1 2 x

2
1

x 2
2
2
x

....
2

(Error: Reference source not found-1)


3 2 x

1 2 2

x
2
2
x

....
2

(Error: Reference source not found-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

(Error: Reference source not found-3)

2
x

1 3 2 2

x 2

(Error: Reference source not found-4)

Hence, in the finite-differences formulation the Poisson-Equation becomes:

1 3 2 2

x 2

f 2

(Error: Reference source not found-5)

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

(Error: Reference source not found-6)

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

(Error: Reference source not found-8)


Including the two boundary conditions at x=0 and x=1, the matrix equation (Error: Reference
source not found-Error: Reference source not found) can be solved using a standard equation
solver.

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.

Three Basic Finite Difference Schemes


There are 3 ways to express differentials of a function f(x):

The forward difference scheme


The rate of the change of the function with respect to the variable x is accounted for
between the current value at:
x = xi and the step forward at x i+1 = x + x

The backward difference scheme


We evaluate the rate of change of the function values between the current step
at xi, and the function value at a step back at xi-1, i.e. x = x x.

The central difference scheme


The rate of change of function f(x) is accounted for between the step at back
at (x-x) and the step ahead of x, i.e. (x+x).

Finite Difference Method (FDM)


Question
Solve for the steady state voltage distribution in a region 0<x<30, 0<y<30, given that one of
the sides of square is excited with a voltage of 45*(x)*(1-x) Volts and all other sides are
maintained at 0 Volts. This voltage at the boundary is symmetrical with its maximum value at
centre of the boundary namely x=15. At any iteration, the value of voltage is updated as
average of voltages of 4 nearest neighbours, until between consecutive iterations, the error is
less than 0.01 V.
Solution
The solution is to solve for the steady state voltage distribution in a region 0<x<30, 0<y<30,
given that one of the sides of square is excited with a voltage of 45*(x)*(1-x) Volts and all
other sides are maintained at 0 Volts. This voltage at the boundary is symmetrical with its
maximum value at centre of the boundary namely x=15. At any iteration, the value of voltage
is updated as average of voltages of 4 nearest neighbours, until between consecutive
iterations, the error is less than 0.01 V. The tolerance in error between iterations is kept at
0.01 V. This may be tweaked to a higher or lower value for lower or higher accuracy
respectively.

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;

%Dimensions of the simulation


grid in x (xdim) and y (ydim)
directions

%Initializing previous (V_prev)


and present (V_now) voltage
matrices
V_now=zeros(xdim+1,ydim+1);
V_prev=zeros(xdim+1,ydim+1);

i=1:1:xdim+1;

%Initializing boundary conditions


only for V_now
%x-co-ordinates for boundary at
y=ydim*grid_size
%A voltage of 45*x*(1-x) is
applied on one boundary, the
remaining
%boundaries are going to remain
at zero volts

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);

%Plot the electric field


distribution
%Quiver command creates a plot,
E=-grad(V), hence the negative
sign

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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

between time and space increment).


FD methods have difficulties concerning the accurate implementation of boundary

conditions (e.g. free surfaces, absorbing boundaries).


FD methods are usually explicit and therefore very easy to implement and efficient on
parallel computers.

FD methods work best on regular, rectangular grids.


As the conclusion, the advantages and disadvantages of Finite Difference Method can

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.

Potrebbero piacerti anche