Challenge

Week 3 - Taylor table method and Matlab code

INTRODUCTION:-

Numerical solution can only give answers at discrete points in the domain which are called as grid points. The finite difference methods is for replacing the partial deravatives appearing in governing equations of fluid dynamics eith algebraic difference quotients yielding a system of algebraic equation which can be solved for the flow field variables at the specific ,discrete grid points in the flow schemes for the fourth order approximation for second order deravative.

SCHEMES FOR FOURTH ORDER APPROXIMATION USING SECOND ORDER DERAVATIVE:-

1. SKEWED CENTRAL DIFFERENCE SCHEME

2. SKEWED RIGHT DIFFERENCE SCHEME

3. SKEWED LEFT DIFFERENCE SCHEME

OBJECTIVE :-

To write a Matlab program to derive the second order deravative analytical function exp(x)*cos(x) and compare it with three numerical approximations

MAIN MATLAB

clear all 
close all
clc
% input variables
x=pi/3;
dx=linspace(pi/10,pi/3000,200);
B1 = [ 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];
A1 = [0 ; 0;2;0;0;0];
X1 = inv(B1)*A1;

% matrices to solve variables for skewed left side difference

B2 = [ 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];
A2 = [ 0 ; 0 ; 2 ; 0 ; 0 ; 0 ];
X2 = inv(B2)*(A2);


% matrices to solve variables for Central differencing
B3 = [ 1 1 1 1 1  ; -2 -1 0 1 2 ; 4 1 0 1 4 ; -8 -1 0 1 8 ; 16 1 0 1 16 ];
A3 = [0 ; 0 ; 2 ; 0 ; 0 ];
X3 = inv(B3)*(A3);


for i=1:length(dx)
    central_diff_value(i) = skewed_central_difference(x,dx(i),X3);
    skewed_right_value(i) = skewed_right_difference(x,dx(i),X1);
    skewed_left_value(i) = skewed_left_difference(x,dx(i),X2);
end
% plot graph
figure(1)
loglog(dx,central_diff_value)
hold on
loglog(dx,skewed_right_value)
loglog(dx,skewed_left_value)
title('absolute error')
legend('central differencing','skewed right','skewed left')
xlabel('Dx')
ylabel('Abolute error')
central difference scheme

function error_skewedcentral = skewed_central_difference(x,dx,X1)
% Given function
% f(x)=exp(x)*cos(x)
% Second order deravative of the function
  Second_order_deravative = -2*exp(x)*sin(x);
% Calculating skewed central difference value
T1 = X1(1)*exp(x-(2*dx))*cos(x-(2*dx));
T2 = X1(2)*exp(x-(1*dx))*cos(x-(1*dx));
T3 = X1(3)*exp(x)*cos(x);
T4 = X1(4)*exp(x+(1*dx))*cos(x+(1*dx));
T5 = X1(5)*exp(x+(2*dx))*cos(x+(2*dx));

skewed_central_difference= (T1+T2+T3+T4+T5)/(dx^2);

% Error Calculation 

error_skewedcentral = abs(Second_order_deravative-skewed_central_difference);
end

right difference scheme

function error_skewedright = skewed_right_difference(x,dx,X2)
% Given function
% f(x)=exp(x)*cos(x)
% Second order deravative of the function
 Second_order_deravative = -2*exp(x)*sin(x);
% Calculating skewed right difference value
T1 = X2(1)*exp(x)*cos(x);
T2 = X2(2)*exp(x+(1*dx))*cos(x+(1*dx));
T3 = X2(3)*exp(x+(2*dx))*cos(x+(2*dx));
T4 = X2(4)*exp(x+(3*dx))*cos(x+(3*dx));
T5 = X2(5)*exp(x+(4*dx))*cos(x+(4*dx));
T6 = X2(6)*exp(x+(5*dx))*cos(x+(5*dx));

skewed_right_difference= (T1+T2+T3+T4+T5+T6)/(dx^2);

% Error Calculation 

error_skewedright = abs(Second_order_deravative-skewed_right_difference);
end

left difference scheme

function error_skewedleft = skewed_left_difference(x,dx,X3)
% Given function
% f(x)=exp(x)*cos(x)
% Second order deravative of the function
 Second_order_deravative = -2*exp(x)*sin(x);
% Calculating skewed left difference value
T1 = X3(1)*exp(x)*cos(x);
T2 = X3(2)*exp(x-(1*dx))*cos(x-(1*dx));
T3 = X3(3)*exp(x-(2*dx))*cos(x-(2*dx));
T4 = X3(4)*exp(x-(3*dx))*cos(x-(3*dx));
T5 = X3(5)*exp(x-(4*dx))*cos(x-(4*dx));
T6 = X3(6)*exp(x-(5*dx))*cos(x-(5*dx));

skewed_left_difference= (T1+T2+T3+T4+T5+T6)/(dx^2);

% Error Calculation 

error_skewedleft = abs(Second_order_deravative-skewed_left_difference);
end

In your own words, describe why a skewed scheme is useful? What can a skewed scheme do that a CD scheme cannot?

When data from the grid points is only available from either the left or right end i.e at the nodes closer to the boundaries for computation that require a high order approximation we make use of skewed scheme having a symmetric stencil for computation is not possible in this scenarios like we do for central difference scheme or having a low order accuracy .For consistency of a scheme to be maintained the values of are kept as low as possible for providing proper computional plots.

CONCLUSION :-

Thus a fourth order approximation are derived for second order dervative making use of Taylor Table method by providing a suitable MATLAB code.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.