Taylor table method
Objectives :-
- Derive the following 4th order approximations of the second order derivative
1) Central difference
2) Skewed right sided difference
3) Skewed left sided difference
- 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 given above.
Inputs :-
Function given, f(x) = exp(x)*cos(x)
Let, x = pi/3
dx = varry from pi/40 to pi/4000
- Analytical second order derivative of the above function
f\"(x) = -2*exp(x)*sin(x)
- Formula to calculate 4th order approximations of the second order derivative by Central difference scheme
f\"(x) = (-0.0833*f(x-2*dx)+1.3333*f(x-dx)-2.5*f(x)+1.3333*f(x+dx)-0.0833* f(x+2*dx))/(dx)^2
- Formula to calculate 4th order approximations of the second order derivative by Skewed right sided difference scheme
f\"(x) = (3.75*f(x)-12.8333*f(x+dx)+17.8333*f(x+2*dx)-13*f(x+3*dx)+5.0833* f(x+4*dx)-0.8333*f(x+5*dx))/(dx)^2
- Formula to calculate 4th order approximations of the second order derivative by Skewed left sided difference scheme
f\"(x) = (-0.8333*f(x-5*dx)+5.0833*f(x-4*dx)-13*f(x-3*dx)+17.8333*f(x-2*dx)- 12.8333*f(x-dx)+3.75*f(x))/(dx)^2
Main program that compute all the three function and plot a graph
close all
clear all
clc
% Input value of x and dx
x = pi/3;
dx = linspace(pi/40,pi/4000,50);
% calculating the value of error in 50 itteration
for i = 1:length(dx)
Central_difference_error(i) = central_approximations(x,dx(i));
Skewed_right_sided_difference_error(i) = Skewed_right_sided_approximations(x,dx(i));
Skewed_left_sided_difference_error(i) = Skewed_left_sided_approximations(x,dx(i));
end
% Ploting the graph to compare the error in all three differences
plot(dx,Central_difference_error,\'color\',\'r\',\'linewidth\',2)
hold on
plot(dx,Skewed_right_sided_difference_error,\'color\',\'b\',\'linewidth\',2)
plot(dx,Skewed_left_sided_difference_error,\'color\',\'g\',\'linewidth\',2)
legend(\'Central difference error\',\'Skewed right sided difference error\',\'Skewed left sided difference error\')
xlabel(\'dx\')
ylabel(\'Truncation Error\')
Function program for calculate 4th order approximations of the second order derivative by Central difference scheme
function Central = central_approximations(x,dx)
% Analytical function = exp(x)*cos(x)
% Analytical second order Derivatives
% f\"(x) = -2*exp(x)*sn(x)
analytical_derivative = -2*exp(x)*sin(x);
% Central difference = (-0.0833*f(x-2*dx)+1.3333*f(x-dx)-2.5*f(x)+1.3333*f(x+dx)-0.0833*f(x+2*dx))/(dx)^2
% Central difference fourth order approximation of second order derivative
Central_difference = (-0.0833*exp(x-2*dx)*cos(x-2*dx)+1.3333*exp(x-dx)*cos(x-dx)-2.5*exp(x)*cos(x)+1.3333*exp(x+dx)*cos(x+dx)-0.0833*exp(x+2*dx)*cos(x+2*dx))/(dx^2);
Central = abs(analytical_derivative - Central_difference);
end
Function program for calculate 4th order approximations of the second order derivative by Skewed right sided difference scheme
function Right_sided = Skewed_right_sided_approximations(x,dx)
% Analytical function = exp(x)*cos(x)
% Analytical second order Derivatives
% f\"(x) = -2*exp(x)*sn(x)
analytical_derivative = -2*exp(x)*sin(x);
% Skewed right sided difference = (3.75*f(x)-12.8333*f(x+dx)+17.8333*f(x+2*dx)-13*f(x+3*dx)+5.0833*f(x+4*dx)-0.8333*f(x+5*dx))/(dx)^2
% Skewed right sided difference fourth order approximation of second order derivative
Skewed_right_sided_difference =(3.75*exp(x)*cos(x)-12.8333*exp(x+dx)*cos(x+dx)+17.8333*exp(x+2*dx)*cos(x+2*dx)-13*exp(x+3*dx)*cos(x+3*dx)+5.0833*exp(x+4*dx)*cos(x+4*dx)-0.8333*exp(x+5*dx)*cos(x+5*dx))/(dx)^2;
Right_sided = abs(analytical_derivative - Skewed_right_sided_difference);
end
Function program for calculate 4th order approximations of the second order derivative by Skewed left sided difference scheme
function Left_sided = Skewed_left_sided_approximations(x,dx)
% Analytical function = exp(x)*cos(x)
% Analytical second order Derivatives
% f\"(x) = -2*exp(x)*sn(x)
analytical_derivative = -2*exp(x)*sin(x);
% Skewed left sided difference = (-0.8333*f(x-5*dx)+5.0833*f(x-4*dx)-13*f(x-3*dx)+17.8333*f(x-2*dx)-12.8333*f(x-dx)+3.75*f(x))/(dx)^2
% Skewed left sided difference fourth order approximation of second order derivative
Skewed_left_sided_difference = (-0.8333*exp(x-5*dx)*cos(x-5*dx)+5.0833*exp(x-4*dx)*cos(x-4*dx)-13*exp(x-3*dx)*cos(x-3*dx)+17.8333*exp(x-2*dx)*cos(x-2*dx)-12.8333*exp(x-dx)*cos(x-dx)+3.75*exp(x)*cos(x))/(dx)^2;
Left_sided = abs(analytical_derivative - Skewed_left_sided_difference);
end
Fig :-
Result and Discussion :-
- In central differences five variable are used to calculate 4th order approximations of the second order derivative.
- In Skewed right sided difference six variable are used to calculate 4th order approximations of the second order derivative.
- In Skewed right sided difference six variable are used to calculate 4th order approximations of the second order derivative.
- From the above graph error in Skewed right sided differences maximum when the value of dx is greater but as the value of dx decreases the value of error also decreases and come approximately constant.
- In Skewed left sided differences maximum when the value of dx is greater but upto the value of dx 0.035 the value of error also decreases after that it again increases and come approximately constant.
- In central differencesthe value of error is approximately constant at every value of dx.
How do these errors compare with FDS and BDS approximations ?
FDS and BDS take information from current point and the right and left neighbouring points and the higher order term neglated by it is dx that is first order. so the error getting by these is more compare to skewed.
It collect the imformation from only 2 neighbouring points left or right and in skewed scheme the information will collect from more then 2 points and neglacting higher order term. so, the error is less in skewed scheme as compare to FDS and BDS.
Describe why a skewed scheme is useful? What can a skewed scheme do that a CD scheme cannot do?
Skewed differences scheme is useful because it work in every condition of nodes avaliablity but central differences not works on the all nodes. For example if there are 5 nodes avaliable then the skewed scheme will calculate from right node as well as from left node but the central difference scheme never calculate at the last node or the corner node. CD scheme always have minimum 1 nodes on its right and left. So the CD never calculate on corner node but the skewed scheme will calculate at all nodes.
Note :- All the value which is calculated by derivation are in attachments.