- For Derivations please find the attached pdf files in the zip-file.
- Observations from the Figure 1:
- Error of Right Sided skewed approximation is greater than that off Left Sided Skewed approximation.
- Error of Left sided skewed approximation is greater than that off Central difference approximation.
- Error values of all 4th order approximations are tending to \'0\' as \'dx\' tends to \'0\'.
- Error of central difference is very very less than that off skewed approximations. This is due to nodes in the neumarical stencil of central difference approximation are more near to the node where we are computing the function value. While in skewed approximations nodes in neumarical stencil are far from the required node.
- Observations from Figure 2:
- Error of FDS is greater than that off BDS.
- Error values of both FDS and BDS are tending to \'0\' as \'dx\' tends to \'0\'.
- Observations from Figure 3:
- Errors of 4th order approximations are very less than compared to first order approximations (FDS and BDS)
- Skewed Approximation vs Central difference:
- Skewed approximations are widely usefull in non-uniform mesh types.
- For Central difference scheme neumarical stencil should be symmetric about the required node where we are computing the function. In many real time cases mesh is not symmetric. For examples, mesh is non-symmetric near the walls.
- Skewed approximations can solve physics of non-symmetric and non-uniform mesh types more accurately than compared to central difference.
- In case of uniform and symmetric mesh types, central difference schemes are very accurate than Skewed.
- In the cases where direction of control volume is known, there skewed difference schemes are useful.
- If control volume is moving from left to right then skewed left sided approximation is more accurate.
- If control volume is moving from righ to left then skewd right sided approximation is more accurate.
- Matlab Code used to solve system of equations of Skewed approximation:
- clear all;
close all;
clc
% Code to solve systems of equations for Fourth-Order Skewed-Left-Side Discretization:
% A = Coefficient Matrix:
A = [1 1 1 1 1 1; 0 -1 -2 -3 -4 -5; 0 1 4 9 16 25; 0 -1 -8 -27 -64 -125; 0 1 16 81 256 625; 0 -1 -32 -243 -1024 -3125];
% B = Constant Matrix;
B = [0; 0; 2; 0; 0; 0];
% C = Inverse of Matrix \'A\':
C = inv(A);
% D = Solution of Variable Matrix:
D = C*B
% Code to solve systems of equations for Fourth-Order Skewed-Right-Side Discretization:
% E = Coefficient Matrix:
E = [1 1 1 1 1 1; 0 1 2 3 4 5; 0 1 4 9 16 25; 0 1 8 27 64 125; 0 1 16 81 256 625; 0 1 32 243 1024 3125];
%F = Constant Matrix;
F = [0; 0; 2; 0; 0; 0];
% G= Inverse of Matrix \'A\':
G = inv(E);
% H = Solution of Variable Matrix:
H = G*F
clear all;
close all;
clc;
% let x = pi/3
x = pi/3;
%given function is f(x) = cos(x)* exp(x):
fx = cos(x)*exp(x);
%let g(x)= exact second deriative of f(x)
gx = -2*exp(x)*sin(x);
dx = linspace(pi/10, pi/40000, 4000);
for i=1:length(dx)
% Fourth order Central difference discretization(FOCDD):
% FOCDD = (-f(x-2) + (16*f(x-1)) - (30*f(x)) + (16*f(x+1)) - f(x+2))/(12(dx^2));
FOCDD(i) = ((-1 * (cos(x-(2*dx(i)))*exp(x-(2*dx(i))))) + (16 * (cos(x-(1*dx(i)))*exp(x-(1*dx(i))))) - (30 * (cos(x+(0*dx(i)))*exp(x+(0*dx(i))))) + (16 * (cos(x+(1*dx(i)))*exp(x+(1*dx(i))))) - (1 * (cos(x+(2*dx(i)))*exp(x+(2*dx(i))))))/(12*((dx(i))^2));
% Fourth order Skewed Right Sided discretization (FOSRSD):
% FOCDD = (3.75f(x) - (12.8333*f(x+1)) + (17.8333*f(x+2)) - (13.0*f(x+3)) + (5.0833*f(x+4)) - (0.8333*f(x+5)))/((dx^2));
FOSRSD(i) = ((3.75 * (cos(x+(0*dx(i)))*exp(x+(0*dx(i))))) - (12.8333 * (cos(x+(1*dx(i)))*exp(x+(1*dx(i))))) + (17.8333 * (cos(x+(2*dx(i)))*exp(x+(2*dx(i))))) - (13 * (cos(x+(3*dx(i)))*exp(x+(3*dx(i))))) + (5.0833 * (cos(x+(4*dx(i)))*exp(x+(4*dx(i))))) - (0.8333 * (cos(x+(5*dx(i)))*exp(x+(5*dx(i)))))) / ((dx(i)^2));
% Fourth order Skewed Left Sided discretization (FOSLSD):
% FOCDD = (3.75f(x) - (12.8333*f(x-1)) + (17.8333*f(x-2)) - (13.0*f(x-3)) + (5.0833*f(x-4)) - (0.8333*f(x-5)))/((dx^2));
FOSLSD(i) = ((3.75 * (cos(x+(0*dx(i)))*exp(x+(0*dx(i))))) - (12.8333 * (cos(x-(1*dx(i)))*exp(x-(1*dx(i))))) + (17.8333 * (cos(x-(2*dx(i)))*exp(x-(2*dx(i))))) - (13 * (cos(x-(3*dx(i)))*exp(x-(3*dx(i))))) + (5.0833 * (cos(x-(4*dx(i)))*exp(x-(4*dx(i))))) - (0.8333 * (cos(x-(5*dx(i)))*exp(x-(5*dx(i)))))) / ((dx(i)^2));
% Forward Difference Scheme (FDS):
% FDS = (f(x) - 2*f(x+1) + f(x+2)) / ((dx)^2);
FDS(i) = ((cos(x)*exp(x))- (2*(cos(x+(dx(i)))*exp(x+(dx(i))))) + (cos(x+(2*(dx(i))))*exp(x+(2*(dx(i)))))) / ((dx(i))^2);
% Backward Difference Scheme (BDS):
% BDS = (f(x) - 2*f(x-1) + f(x-2)) / ((dx)^2);
BDS(i) = ((cos(x)*exp(x))- (2*(cos(x-(dx(i)))*exp(x-(dx(i))))) + (cos(x-(2*(dx(i))))*exp(x-(2*(dx(i)))))) / ((dx(i))^2);
%ERRORS:
% Fourth order Central difference discretization Error(FOCDDE):
FOCDDE(i) = abs(gx - FOCDD(i));
% Fourth order Skewed Right Sided discretization Error (FOSRSDE):
FOSRSDE(i) = abs(gx - FOSRSD(i));
% Fourth order Skewed Left Sided discretization Error (FOSLSDE):
FOSLSDE(i) = abs(gx - FOSLSD(i));
% Forward Difference Scheme Errpr (FDSE):
FDSE(i) = abs(gx - FDS(i));
% Backward Difference Scheme Error (BDSE):
BDSE(i) = abs(gx - BDS(i));
end
% Figure# 1: Comparing 4th Order Disretizations (Central, Skewed Right, Skewed Left) Errors of 2nd Order derivative:
figure(1)
plot(dx, FOCDDE, \'b\')
hold on
plot(dx, FOSRSDE, \'g\')
hold on
plot(dx, FOSLSDE, \'r\')
xlabel(\'dx\')
ylabel(\'ERROR VALUE\')
legend(\'Fourth order Central difference discretization Error\', \' Fourth order Skewed Right Sided discretization Error\', \' Fourth order Skewed Left Sided discretization Error\')
% Figure# 2: Comparing 1st Order Disretizations (FDS, BDS) Errors of 2nd Order derivative:
figure(2)
plot(dx, FDSE, \'c\')
hold on
plot(dx, BDSE, \'m\')
xlabel(\'dx\')
ylabel(\'ERROR VALUE\')
legend(\'Forward Difference Scheme\', \'Backward Differebce Sheme\')
% Figure# 3: Comparing 4th Order Disretizations (Central, Skewed Right, Skewed Left) Errors and 1st Order Disretizations (FDS, BDS) Errors of 2nd Order derivative:
figure(3)
plot(dx, FOCDDE, \'b\')
hold on
plot(dx, FOSRSDE, \'g\')
hold on
plot(dx, FOSLSDE, \'r\')
hold on
plot(dx, FDSE, \'c\')
hold on
plot(dx, BDSE, \'m\')
xlabel(\'dx\')
ylabel(\'ERROR VALUE\')
legend(\'Fourth order Central difference discretization Error\', \' Fourth order Skewed Right Sided discretization Error\', \' Fourth order Skewed Left Sided discretization Error\', \'Forward Difference Scheme\', \'Backward Differebce Sheme\')