Taylor table
In order to find the approximatios for the given scheme
Firstly, we establish the stencil that are used to calculate the scheme.
a) Central Difference Scheme (i-2,i-1,i,i+1,i+2)
b) Skewed right sided difference (i,i+1,i+2,i+3,i+4)
c) Skewed left sided difference(i,i-1,i-2,i-3,i-4)
Using taylor series expansion , we can write
`f(i+1)=f(i)+f\'(i)dx+f\'\'(i)dx^2/2+f\'\'\'(i)dx^3/6+f\'\'\'\'(i)dx^4/24`
`f(i-1)=f(i)-f\'(i)dx+f\'\'(i)dx^2/2-f\'\'\'(i)dx^3/6+f\'\'\'\'(i)dx^4/24`
`f(i+2)=f(i)+2f\'(i)dx+2f\'\'(i)dx^2+4/3f\'\'\'(i)dx^3+2/3f\'\'\'\'(i)dx^4`
`f(i-2)=f(i)-2f\'(i)dx+2f\'\'(i)dx^2-4/3f\'\'\'(i)dx^3+2/3f\'\'\'\'(i)dx^4`
`f(i+3)=f(i)+3f\'(i)dx+9/2f\'\'(i)dx^2+9/2f\'\'\'(i)dx^3+27/8f\'\'\'\'(i)dx^4`
`f(i-3)=f(i)-3f\'(i)dx+9/2f\'\'(i)dx^2-9/2f\'\'\'(i)dx^3+27/8f\'\'\'\'(i)dx^4`
`f(i+4)=f(i)+4f\'(i)dx+8f\'\'(i)dx^2+32/3f\'\'\'(i)dx^3+32/3f\'\'\'\'(i)dx^4`
`f(i-4)=f(i)-4f\'(i)dx+8f\'\'(i)dx^2-32/3f\'\'\'(i)dx^3+32/3f\'\'\'\'(i)dx^4`
These expansions are futher used in the approximations.
a) Central Difference Scheme
`(delta^2f)/(deltax^2)=(af(i-2)+bf(i-1)+cf(i)+df(i+1)+ef(i+2))/dx^2+O(dx^4)`
`Using the above expansions we obtain a taylor table of the form `
|
f (i) |
f ‘(i) |
f’’ (i) |
f’’’ (i) |
f ‘’’’(i) |
|
|
f(i) |
c |
0 |
0 |
0 |
0 |
|
f(i+1) |
d |
d |
d/2 |
d/6 |
d/2 |
|
f(i+2) |
e |
2e |
2e |
4e/3 |
2e/3 |
|
f(i-1) |
b |
-b |
b/2 |
-b/6 |
b/24 |
|
f(i-2) |
a |
-2a |
2a |
-4a/3 |
2a/3 |
Representing the above table in matrix form , we get.
`[[a],[b],[c],[d],[e]] [[1,1,1,1,1],[-2,-1,0,1,2],[2,1/2,0,1/2,2],[-4/3,-1/6,0,1/6,4/3],[2/3,1/24,0,1/24,2/3]]= [[0],[0],[1],[0],[0]]`
Solving the equation using MATLAB , we get
a=-0.0833
b=1.333
c=-2.5
d=1.33
e=-0.0833
`Hence the equation reduces to `
`(delta^2f)/(deltax^2)=(-0.0833f(i-2)+1.333f(i-1)-2.5f(i)+1.333f(i+1)-0.08333f(i+2))/dx^2+O(dx^4)``
The given equation is further employed in MATLAB to solve the given equation.
b) Skewed right sided difference
`(delta^2f)/(deltax^2)=(af(i)+bf(i+1)+cf(i+2)+df(i+3)+ef(i+4))/dx^2+O(dx^4)`
`Using the above expansions we obtain a taylor table of the form `
|
f (i) |
f ‘(i) |
f’’ (i) |
f’’’ (i) |
f ‘’’’(i) |
|
|
f(i) |
a |
0 |
0 |
0 |
0 |
|
f(i+1) |
b |
b |
b/2 |
b/6 |
b/2 |
|
f(i+2) |
c |
2c |
2c |
4c/3 |
2c/3 |
|
f(i+3) |
d |
3d |
9d/2 |
9d/2 |
27d/8 |
|
f(i+4) |
e |
4e |
8e |
32e/3 |
32e/3 |
`[[a],[b],[c],[d],[e]] [[1,1,1,1,1],[0,1,2,3,4],[0,1/2,2,9/2,8],[0,1/6,4/3,9/2,32/3],[0,1/24,2/3,27/8,32/3]]= [[0],[0],[1],[0],[0]]`
Solving the equation using MATLAB , we get
a=2.9167
b=-8.6667
c=9.5000
` d= -4.666`
e=0.9167
`Hence the equation reduces to `
`(delta^2f)/(deltax^2)=( 2.9167f(i)-8.6667f(i+1)+ 9.5000f(i+2)-4.6667f(i+3)+ 0.9167(i+4))/dx^2+O(dx^4)```
c) Skewed left sided difference
`(delta^2f)/(deltax^2)=(af(i)+bf(i-1)+cf(i-2)+df(i-3)+ef(i-4))/dx^2+O(dx^4)`
`Using the above expansions we obtain a taylor table of the form `
|
f (i) |
f ‘(i) |
f’’ (i) |
f’’’ (i) |
f ‘’’’(i) |
|
|
f(i) |
a |
0 |
0 |
0 |
0 |
|
f(i+1) |
b |
-b |
b/2 |
-b/6 |
b/2 |
|
f(i+2) |
c |
-2c |
2c |
-4c/3 |
2c/3 |
|
f(i+3) |
d |
-3d |
9d/2 |
-9d/2 |
27d/8 |
|
f(i+4) |
e |
-4e |
8e |
-32e/3 |
32e/3 |
`[[a],[b],[c],[d],[e]] [[1,1,1,1,1],[0,-1,-2,-3,-4],[0,1/2,2,9/2,8],[0,-1/6,-4/3,-9/2,-32/3],[0,1/24,2/3,27/8,32/3]]= [[0],[0],[1],[0],[0]]`
Solving the equation using MATLAB , we get
a=2.9167
b=-8.6667
c=9.5000
` d= -4.666`
e=0.9167
`Hence the equation reduces to `
`(delta^2f)/(deltax^2)=( 2.9167f(i)-8.6667f(i-1)+ 9.5000f(i-2)-4.6667f(i-3)+ 0.9167(i-4))/dx^2+O(dx^4)```
Results:-
%%Code to solve for the values of a, b, c , d, e
[A]=[1 1 1 1 1 ;0 -1 -2 -3 -4;0 1/2 2 9/2 8; 0 -1/6 -4/3 -9/2 -32/3;0 1/24 2/3 27/8 32/3];
[B]=[0; 0; 1; 0; 0];
X=linsolve(A,B);
%%Function for central difference
function [error1] = central_difference(x,dx)
%%Analytical value
fana=-2*exp(x)*sin(x);
%%central_difference scheme (i,i-1,i-2,i+1,i+2)
central= (16*(exp(x+dx)*cos(x+dx) + exp(x-dx)*cos(x-dx)) - (exp(x+2*dx)*cos(x+2*dx) + exp(x-2*dx)*cos(x-2*dx)) - (30*exp(x)*cos(x)))/(12*dx^2);
%%Calculating the error
error1= abs(central - fana);
end
%%Function for Skewed right sided difference
function [error2] = skewed_right(x,dx)
%%Analytical value
fana=-2*exp(x)*sin(x);
%%Skewed right sided (i,i+1,i+2,i+3,i+4)
skewedr = (35*exp(x)*cos(x) - 104*exp(x+dx)*cos(x+dx)+ 114*exp(x+2*dx)*cos(x+2*dx) - 56*exp(x+3*dx)*cos(x+3*dx) +11*exp(x+4*dx)*cos(x+4*dx))/(12*(dx^2));
%Truncation Error
error2 = abs(skewedr-fana);
end
%%Function for Skewed left sided difference
function [error3] = skewed_left(x,dx)
%%Analytical value
fana=-2*exp(x)*sin(x);
%%Skewed left sided (i,i-1,i-2,i-3,i-4)
skewedl = (35*exp(x)*cos(x) - 104*exp(x-dx)*cos(x-dx)+ 114*exp(x-2*dx)*cos(x-2*dx) - 56*exp(x-3*dx)*cos(x-3*dx) + 11*exp(x-4*dx)*cos(x-4*dx))/(12*(dx^2));
%Truncation Error
error3 = abs(skewedl-fana);
end
%%Function for forward difference
function error4 = forward_difference(x,dx)
%%Analytical value
fana=-2*exp(x)*sin(x);
%%Forward difference
forward= (exp(x+dx)*cos(x+dx)-exp(x)*cos(x))/dx;
%Truncation Error
error4 = abs(forward-fana);
end
%%%%Function for backward difference
function error5 = backward_difference(x,dx)
%%Analytical value
fana=-2*exp(x)*sin(x);
%%Forward difference
backward= (exp(x)*cos(x)-exp(x-dx)*cos(x-dx))/dx;
%Truncation Error
error5 = abs(backward-fana);
end
%%Main run file
close all
clear all
clc
%%Assuming x=pi/4
x = pi/4;
%%Defining the grid size
dx=linspace(pi/10,pi/250,10);
%Calculating error
for i = 1:length(dx)
error_central(i) =central_difference(x,dx(i));
error_right(i) = skewed_right(x,dx(i));
error_left(i)=skewed_left(x,dx(i));
error_forward(i)=forward_difference(x,dx(i));
error_backward(i)=backward_difference(x,dx(i));
end
figure(1)
loglog(dx,error_central ,\'k\',\'linewidth\', 1.5);
hold on
loglog(dx,error_right ,\'k--\',\'linewidth\', 1.5);
hold on
loglog(dx,error_left ,\'k-o\',\'linewidth\', 1.5);
xlabel(\'step size\')
ylabel(\'Error due to truncation\')
title(\'Comparision between different schemes for a second order derivative of 4th order accuracy\')
legend(\'Central difference\',\'Skewed right sided difference\',\' Skewed left sided difference\')
%%Figure(2)
figure(2)
loglog(dx,error_central ,\'k\',\'linewidth\', 1.5);
hold on
loglog(dx,error_right ,\'k--\',\'linewidth\', 1.5);
hold on
loglog(dx,error_left ,\'k-o\',\'linewidth\', 1.5);
hold on
loglog(dx,error_forward ,\'k-*\',\'linewidth\', 0.5);
hold on
loglog(dx,error_backward ,\'r\',\'linewidth\', 0.5);
xlabel(\'step size\')
ylabel(\'Error due to truncation\')
title(\'Comparision between different schemes for a second order derivative of 4th order accuracy and FD and BD\')
legend(\'Central difference\',\'Skewed right sided difference\',\' Skewed left sided difference\',\'Forward difference\',\'Backward difference\')
Inferences:-
1) It can be seen from figure 1 that the central difference scheme tends to give the most minimum error where as the other two schemes tend to have a relatively higher value of error.
2) In comparision to the first order foward difference scheme the second oreder schemes haave minimum error as seen in the Figure 2.
3) For the current case , the central difference scheme turns out to be more accurate than the skewed schemes but for problems with more complexity there is a chance that central difference scheme can produce more ringing. In such cases , the skewewd schemes tend to be more useful.