Week 3.5 - Deriving 4th order approximation of a 2nd order derivative using Taylor Table method
Aim: Derive the following 4th order approximations of the second-order derivative.
1. Central difference
2. Skewed right-sided difference
3. Skewed left-sided difference
After deriving these schemes, prove that your skewed schemes are fourth-order accurate i.e the thumb rule given in HINT (ii).
Once you have done this, write a program in Matlab to evaluate the second-order derivative of the analytical function exp(x)*cos(x) and compare it with the 3 numerical approximations that you have derived.
Provide a plot that compares the absolute error between the above-mentioned schemes
In your own words, describe why a skewed scheme is useful? What can a skewed scheme do that a CD scheme cannot?
Function:
Taylor series:
af(i-2) = a*f(i)-(2*a*f'(i)*dx/1!)+(4*a*f''(i)*dx^2/2!)+(8*a*f'''(i)*dx^3/3!)+(16*a*f''''(i)*dx^4/4!)
Central difference 4th order approximation:
d^2f/dx^2 = a*f(i-2)+b*f(i-1)+c*f(i)+d*(i+1)+e*f(i+2)
| f(i) | f'(i)*dx | f''(i)*dx^2 | f'''(i)*dx^3 | f''''(i)*dx^4 | f'''''(i)*dx^5 | |
| a*f(i-2) | a | -2a | 4a/2 | -8a/6 | 16a/24 | -32a/120 |
| b*f(i-1) | b | -b | b/2 | -b/6 | b/24 | -b/120 |
| c*f(i) | c | 0 | 0 | 0 | 0 | 0 |
| d*f(i+1) | d | d | d/2 | d/6 | d/24 | d/120 |
| e*f(i+2) | e | 2e | 4e/2 | 8e/6 | 16e/24 | 32e/120 |
| sum of coefficients | 0 | 0 | 1 | 0 | ? | ? |
Values of 4th order differences:
a = -0.0833
b = 1.3333
c = -2.5000
d = 1.3333
e = -0.0833

Skewed Right Sided Difference:
d^2f/dx^2 = a*f(i)+b*f(i+1)+c*f(i+2)+d*(i+3)+e*f(i+4)+f*f(i+5)/dx^2
| f(i) | f'(i)*dx | f''(i)*dx^2 | f'''(i)*dx^3 | f''''(i)*dx^4 | f'''''(i)*dx^5 | |
| a*f(i) | a | 0 | 0 | 0 | 0 | 0 |
| b*f(i+1) | b | b | b/2 | b/6 | b/24 | b/120 |
| c*f(i+2) | c | 2c | 4c/2 | 8c/2 | 16c/24 | 32c/120 |
| d*f(i+3) | d | 3d | 9d/2 | 27d/6 | 81d/24 | 243d/120 |
| e*f(i+4) | e | 4e | 16e/2 | 64e/6 | 256e/24 | 1024e/120 |
| sum of coefficients | 0 | 0 | 1 | 0 | ? | ? |
Values of Skewed Right Sided Difference:
a =2.91667
b = -8.6667
c = 9.5000
d = 4.6667
e = 0.91667
Skewed Left Sided Difference:
d^2f/dx^2 = a*f(i-5)+b*f(i-4)+c*f(i-3)+d*(i-2)+e*f(i-1)+f*f(i)/dx^2
| f(i) | f'(i)*dx | f''(i)*dx^2 | f'''(i)*dx^3 | f''''(i)*dx^4 | f'''''(i)*dx^5 | |
| a*f(i-5) | a | -5a | 25a/2 | -125a/6 | 625a/24 | -3125a/120 |
| b*f(i-4) | b | -4b | 16b/2 | -64b/6 | 256b/24 | -1024b/120 |
| c*f(i-3) | c | -3c | 9c/2 | -27c/6 | 81c/24 | -243c/120 |
| d*f(i-2) | d | -2d | 4d/2 | -8d/6 | 16d/24 | -32d/120 |
| e*f(i-1) | e | -e | e/2 | -e/6 | e/24 | -e/120 |
| sum of coefficients | 0 | 0 | 1 | 0 | ? | ? |
Values of Skewed Left Sided Difference:
a = 0.91667
b = -4.6667
c = 9.5000
d = -8.6667
e = 2.9167
Main Code:
close all
clear all
clc
x = pi/3;
dx = linspace(pi/4,pi/40,20);
for i=1:length(dx)
fourth_ord(i) = fourth_central(x,dx(i));
skewed_rig(i) = Right_skewed_approximation(x,dx(i));
skewed_lef(i) = Left_skewed_approximation(x,dx(i));
end
loglog(dx,fourth_ord,'k')
hold on
loglog(dx,skewed_rig,'b')
loglog(dx,skewed_lef,'r')
hold off
legend('fourth_ord','skewed_rig','skewed_lef')
xlabel('dx')
ylabel('Error')
Function of Fourth order approximation:
function error_1 = fourth_central(x,dx)
% Analytical function = exp(x)*cos(x)
% f''(x) = -2*sin(x)*exp(x)
analytical_derivative = -2*sin(x)*exp(x);
% Numerical derivative
central_diff = ((-0.0833*cos(x-2*dx)*exp(x-2*dx))+(1.3333*cos(x-dx)*exp(x-dx))+(-2.5*cos(x)*exp(x))+(1.3333*cos(x+dx)*exp(x+dx))+(-0.0833*cos(x+2*dx)*exp(x+2*dx)))/dx^2;
error_1 = abs(analytical_derivative - central_diff)
end
Function of Skewed Right Sided Difference:
function error_2 = Right_skewed_approximation(x,dx)
% Analytical function = exp(x)*cos(x)
% f''(x) = -2*sin(x)*exp(x)
analytical_derivative = -2*sin(x)*exp(x);
% Numerical derivative
right_skewed = ((2.9167*cos(x)*exp(x))+(-8.667*cos(x+dx)*exp(x+dx))+(9.5*cos(x+2*dx)*exp(x+2*dx))+(-4.667*cos(x+3*dx)*exp(x+3*dx))+(0.9167*cos(x+4*dx)*exp(x+4*dx)))/dx^2;
error_2 = abs(analytical_derivative - right_skewed)
end
Function of Skewed Left Sided Difference:
function error_3 = Left_skewed_approximation(x,dx)
% Analytical function = exp(x)*cos(x)
% f''(x) = -2*sin(x)*exp(x)
analytical_derivative = -2*sin(x)*exp(x);
% Numerical derivative
left_skewed = ((0.91667*cos(x)*exp(x))+(-4.667*cos(x-dx)*exp(x-dx))+(9.5*cos(x-2*dx)*exp(x-2*dx))+(-8.667*cos(x-3*dx)*exp(x-3*dx))+(2.9167*cos(x-4*dx)*exp(x-4*dx)))/dx^2;
error_3 = abs(analytical_derivative - left_skewed)
end
Output:
error_1 =
0.0888
error_2 =
22.2928
error_3 =
4.1856
error_1 =
0.0729
error_2 =
18.3491
error_3 =
4.3024
Plot:

1.1 In your own words, describe why a skewed scheme is useful?
The system which doesn’t contain sufficient information on both side of the point of interest. In such cases we cannot use central differencing scheme so skewed scheme is useful in such cases.
1.2 What can a skewed scheme do that a CD scheme cannot?
CDS cannot not be employed at the boundary nodes due to unavailability of right and left nodes at the same time. In such cases the skewed differencing scheme is used.
Conclusion:
1. We successfully run the Matlab code for centre difference,Skewed right sided difference and Skewed left sided difference respectively.
2. We successfully plot the require graph.