Professional Documents
Culture Documents
Assignment 1 CFD 1a C PDF
Assignment 1 CFD 1a C PDF
........................................................................................................................................ 1
Comparison of accuracy of the results by various numerical differencing techniques and the actual
differentiation ..................................................................................................................... 1
First Order Exact Differentiation by Calculus ........................................................................... 2
First Order Finite Differencing by Forward Differencing Method ................................................. 3
First Order Finite Differencing by Backward Diffrencing Method ................................................ 4
First Order Finite Differencing by Central Diffrencing Method ................................................... 5
Second Order Exact Differentiation by Calculus ....................................................................... 6
Second Order Finite Differencing by Forward Differencing Method ............................................. 7
Second Order Finite Differencing by Backward Diffrencing Method ............................................ 8
Second Order Finite Differencing by Central Diffrencing Method ................................................ 9
Plotting Parameters .............................................................................................................. 9
End of MATLAB Programme ............................................................................................. 10
clear;
clc;
delx=0.1;
% Assign the span of boundary function dimension
x=[0:delx:2];
% Assign the boundary function
f=exp(2*x);
% Plot the boundary function
plot(x,f,'--r','LineWidth',3);
hold on;
1
First Order Exact Differentiation by Calculus
Assign the first order exact derivative of boundary function
g=2*exp(2*x);
% Plot of first order exact derivative
plot(x,g,'k','LineWidth',2);
hold on;
2
First Order Finite Differencing by Forward Dif-
ferencing Method
Assign the field function as per first order forward numerical differencing
fnumfd=(f(3:end)-f(2:end-1))/delx;
% Plot of first order numerical forward difference derivative of
boundary function
plot(x(2:end-1),fnumfd,'b','LineWidth',2);
hold on;
3
First Order Finite Differencing by Backward
Diffrencing Method
Assign the field function as per first order backward numerical differencing
fnumbd=(f(2:end-1)-f(1:end-2))/delx;
% Plot of first order numerical backward difference derivative of
boundary function
plot(x(2:end-1),fnumbd,'g','LineWidth',2);
hold on;
4
First Order Finite Differencing by Central
Diffrencing Method
Assign the field function as per first order central numerical differencing
fnumcd=(f(3:end)-f(1:end-2))/(2*delx);
% Plot of first order numerical central difference derivative of
boundary function
plot(x(2:end-1),fnumcd,'r','LineWidth',2);
hold on;
5
Second Order Exact Differentiation by Calculus
Assign the second order exact derivative of boundary function
h=4*exp(2*x);
% Plot of first order exact derivative
plot(x,h,'k','LineWidth',1);
hold on;
6
Second Order Finite Differencing by Forward
Differencing Method
Assign the field function as per second order forward numerical differencing
gnumfd=(f(3:end)-(2.*f(2:end-1))+f(1:end-2))/(delx.*delx);
% Plot of second order numerical forward difference derivative of
boundary function
plot(x(2:end-1),gnumfd,'b','LineWidth',1);
hold on;
7
Second Order Finite Differencing by Backward
Diffrencing Method
Assign the field function as per second order backward numerical differencing
gnumbd=(f(3:end-1)-(2.*f(2:end-2))+f(1:end-3))/(delx.*delx);
% Plot of second order numerical backward difference derivative of
boundary function
plot(x(2:end-2),gnumbd,'g','LineWidth',1);
hold on;
8
Second Order Finite Differencing by Central
Diffrencing Method
Assign the field function as per second order central numerical differencing
gnumcd=(-f(5:end)+(16.*f(4:end-1))-(30.*f(3:end-2))+(16.*f(2:end-3))-
f(1:end-4))/(12*delx.*delx);
% Plot of second order numerical central difference derivative of
boundary function
plot(x(3:end-2),gnumcd,'r','LineWidth',1);
hold on;
Plotting Parameters
xlabel('X axis');
ylabel('Function value');
legend('Boundary Function','First Order Exact Derivative','First
Order Forward Diffrencing Method','First Order Backward Differencing
Method','First Order Central Differencing Method','Second Order Exact
Derivative','Second Order Forward Differencing Method','Second Order
Backward Differencing Method','Second Order Central Differencing
Method');
grid on;
9
End of MATLAB Programme
Published with MATLAB® R2018b
10