SOLUTION FOR SECOND ORDER DERIVATIVE USING TAYLOR TABLE APPROXIMATION METHOD
Taylor series is a approximation method for solving a function at a small incremental value for the function .
The above equation is employed in solving our stencils. Let us examine the approximation method for a second order derivative of a function and compare the results .The three different scheme that we have are central difference, right skewed and left skewed . the figure details the explanation of what these schemes look like and the approach towards solving the function .
A- Right handed skewed
B- Central difference scheme
C- Left handed skewed system
The number of stencils to be taken is given by a general equation.
Skewed = A+B;
Central scheme =A+B-1;
Where A= order of derivative.
B= order of approximation
Therefore for solving a second order derivative and a fourth order approximation the number of cells are given as six and five for skewed and central difference respectively. With the given information lets solve the function and find the error pertaining to the different schemes.
- Right handed skewed scheme
βπ^2.π′′(π) = π.π(π) + π.π(π + π) + π.π(π + π) + π .π(π + π) + π.π(π + π) + π.π(π + π).
Now we have derived the equation for the right skewed system we have to employ Taylors series to solves each and every term but we can simply by using Taylor’s table method and solve them .
We take out the corresponding values of coefficient and create a matrix and solve them to get the exact values of them ,it’s a linear equations with 6 unknowns and 6 equations .
ο· Left handed skewed system
βπ^2.π′′(π) = π.π(π − π) + π.π(π − π) + π.π(π − π) + π .π(π − π) + π.π(π − π) + π.π(π).
- Central difference scheme
using the above values we can code a program to compute the analytical derivative and the approximation method of the three system we are intented .
Applying
- right handed skewed system
The solution obtained for the coeffients are
a = 3.75
b=-12.833
c=17.833
d=-13.0
e=5.0833
f=-0.833
We use inverse function in matlab to solve the the matrix and obtain the coeffients ,since we are doing an approximation methods we keep the values in fraction because the error may amplify and lead us to wrong results hence once the coefficient array is generated we index the value and use it for substitution in the equation .
By this way we can get to know how the error play with the three schemes we are discussing .
Let us examine a function to know better and the function be (exp(x)*cos(x));
Analytical derivative =-2*(exp(x))*sin(x);
A function is called upon to evaluate the analytical and three schemes and campare the reults at a value of X=pi/3;and varying the value of dx from pi/40 to pi/4000 and plotting the variation of dx and the error of that particular value of dx by creating a for loop that operates on each and every value of dx and provides the error terms for all the three . the codes has been attached below
We can clearly see that error is very less for central difference when we compare that with left skewed and right skewed for the same value of X and variation of dx is show .the expalanation is simple because it employes information from the left and right cells of the function that is discretized .
The same process is repeated for left and right scheme which is eloberated and explained in the report that is attached to the file .
to understand why sckewed scheme are fourth order
***************************************
function out =right_skewed(x,dx)
A=[1 1 1 1 1 1;0 1 2 3 4 5;0 1/2 4/2 9/2 16/2 25/2;0 1/6 8/6 27/6 64/6 125/6;0 1/24 16/24 81/24 256/24 625/24;0 1/120 32/120 243/120 1024/120 3125/120];
B=[0;0;1;0;0;0];
[c]=inv(A)*B;
analytical_derivative=-2*(exp(x))*sin(x);
rightskewed=(c(6,1)*(exp(x+(5*dx))*cos(x+(5*dx)))+c(5,1)*(exp(x+(4*dx))*cos(x+(4*dx)))+c(4,1)*(exp(x+(3*dx))*cos(x+(3*dx)))+(c(3,1)*(exp(x+(2*dx))*cos(x+(2*dx))))+c(2,1)*(exp(x+(1*dx))*cos(x+(1*dx)))+c(1,1)*(exp(x)*cos(x)))/(dx^2);
out=abs(analytical_derivative-rightskewed);
end
******************************************
function out =left_skewed(x,dx)
A=[1 1 1 1 1 1;-5 -4 -3 -2 -1 0;25/2 16/2 9/2 4/2 1/2 0;-125/6 -64/6 -27/6 -8/6 -1/6 0;625/24 256/24 81/24 16/24 1/24 0;-3125/120 -1024/120 -243/120 -32/120 -1/120 0];
B=[0;0;1;0;0;0];
[c]=inv(A)*B;
analytical_derivative=-2*(exp(x))*sin(x);
leftskewed=(c(1,1)*(exp(x-(5*dx))*cos(x-(5*dx)))+(c(2,1)*(exp(x-(4*dx))*cos(x-(4*dx))))+(c(3,1)*(exp(x-(3*dx))*cos(x-(3*dx))))+(c(4,1)*(exp(x-(2*dx))*cos(x-(2*dx))))+c(5,1)*(exp(x-(1*dx))*cos(x-(1*dx)))+c(6,1)*(exp(x)*cos(x)))/(dx^2);
out=abs(analytical_derivative-leftskewed);
end
*******************************************
function out =left_skewed(x,dx)
A=[1 1 1 1 1 1;-5 -4 -3 -2 -1 0;25/2 16/2 9/2 4/2 1/2 0;-125/6 -64/6 -27/6 -8/6 -1/6 0;625/24 256/24 81/24 16/24 1/24 0;-3125/120 -1024/120 -243/120 -32/120 -1/120 0];
B=[0;0;1;0;0;0];
[c]=inv(A)*B;
analytical_derivative=-2*(exp(x))*sin(x);
leftskewed=(c(1,1)*(exp(x-(5*dx))*cos(x-(5*dx)))+(c(2,1)*(exp(x-(4*dx))*cos(x-(4*dx))))+(c(3,1)*(exp(x-(3*dx))*cos(x-(3*dx))))+(c(4,1)*(exp(x-(2*dx))*cos(x-(2*dx))))+c(5,1)*(exp(x-(1*dx))*cos(x-(1*dx)))+c(6,1)*(exp(x)*cos(x)))/(dx^2);
out=abs(analytical_derivative-leftskewed);
end
*******************************
function out =central_difference(x,dx)
A=[1 1 1 1 1;-2 -1 0 1 2;2 0.5 0 0.5 2;-4/3 -1/6 0 1/6 4/3;2/3 1/24 0 1/24 2/3];
B=[0;0;1;0;0];
[c]=inv(A)*B;
analytical_derivative=-2*(exp(x))*sin(x);
centraldiff=(c(1,1)*(exp(x-(2*dx))*cos(x-(2*dx)))+c(2,1)*(exp(x-dx)*cos(x-dx))+c(3,1)*(exp(x)*cos(x))+c(4,1)*(exp(x+dx)*cos(x+dx))+c(5,1)*(exp(x+(2*dx))*cos(x+(2*dx))))/(dx^2);
out=abs(analytical_derivative-centraldiff);
end
******************************* The main program
close all
clear all
clc
x=pi/3;
dx=linspace(pi/40,pi/400,5)
for i= 1:length(dx)
cd_error(i)=central_difference(x,dx(i));
r_error(i)=right_skewed(x,dx(i));
l_error(i)=left_skewed(x,dx(i));
end
figure(1)
loglog(dx,cd_error)
hold on
loglog(dx,r_error)
hold on
loglog(dx,l_error)
grid on
legend(\'centaldiff-errror\',\'right-skewederror\',\'left-skewederror\')
******************
The results of the coeffient matrix
right skewed
a=3.7500
b=-12.833
c=17.833
d=-13.00
e=5.083
f=-0.8333
left skewed
f=3.7500
e=-12.833
d=17.833
c=-13.00
b=5.083
a=-0.8333
central difference
a=-0.0833
b=1.333
c=-2.5
d=1.333
e=-0.8333
We can clearly see that error is very less for central difference when we compare that with left skewed and right skewed for the same value of X and variation of dx is show .the expalanation is simple because it employes information from the left and right cells of the function that is discretized .