You are on page 1of 2

National University of Sciences and Technology

College of Electrical & Mechanical Engineering


Assignment-1: Computational Fluid Dynamics-I
Accuracy of Finite Difference Schemes
The second order finite difference approximations for the following derivatives, on a uniform
mesh, are given as following:
df
fi+1 fi1
+ O(x)2
=
dx i
2x
fi+1 2fi + fi1
d2 f
+ O(x)2
=
2
dx i
(x)2
d3 f
fi+2 2fi+1 + 2fi1 fi2
+ O(x)2
=
3
dx i
2(x)3
The analytic function is given as:
f (x) = x3 5x
The function derivative is to be evaluated at x = 0.5.
The error in exact and approximate derivative is calculated as:



df
df

Error = (exact)
(appr)
dx i
dx i

Tasks
d3 f
shown above.
dx3
(b) Write a computer program to calculate the derivative using the above mentioned schemes
for the following values of x.
(a) Derive the second-order finite difference approximation for

x = 0.3, 0.2, 0.1, 0.01, 0.005, 0.001, 0.0005, 0.0001


(c) Calculate the error between exact derivative and approximate derivative, at x = 0.5, for
various x values.
(d) Plot the error, calculated in Step 3, as a function of grid spacing on logarithmic scale on
both axis. The errors from all the three FDA should be plotted on the same graph to see
the magnitude of error. Discuss your findings about the variations (slope of lines) of error
for different numerical approximations.

Submission Guidelines
The soft copy of this assignment, along with computer program, should be submitted
latest by 05/10/2013.
To submit your program, include the source code, executable and a description of program.
The description must include the flowchart of the program and the guidelines on how to
run your source code.
Any programming language (Fortran,C/C++, Matlab,... ) can be used for coding.

Programming Guidelines/Tips:
Use arrays to define different x, the three FDA and the three errors. For example the
syntax of defining an array for different x can be written in Matlab as following:
dx=[0.3 0.2 0.1 0.01 0.005 0.001 0.0005 0.00001];
Use a Do loop to calculate the three FDA and the three errors.
Logarithmic axis can be called in Matlab for both x and y axis by using loglog command.
For example the syntax to plot x array vs y array:
loglog(x,y)
hold on can be use in Matlab to plot multiple plots on the same graph.

You might also like