Project

Taylor table method and Matlab code

Taylor table method and Matlab code

Observation :-

Derive the following 4th order approximations of the second-order derivative.

1. Central difference

2. Skewed right-sided difference

3. Skewed left-sided difference

Also, prove that your skewed schemes are fourth-order accurate.

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.

Inputs :-

  • Function given is , f(x) = exp(x)*cos(x).
  • Let , x= pi/3 & dx = pi/40 to pi/4000.
  • Analytical second order derivative equation f"(x) = -2*exp(x)*sin(x).
  • Formula to calculate the 4th order approximations of the second order derivative by central difference scheme (cds).
  • a=-1/2, b=4/3, c=-5/2, d=4/3, e=-1/12
  • cds_skewed = ((ca*left_2)+(cb*left_1)+(cc*point)+(cd*right_1)+(ce*right_2))/((dx(i))^2);
  • Formula to calculate the 4th order approximations of the second order derivative by forward difference scheme (fds).
  • a=15/4, b=-77/6, c=107/6, d=13, e=61/12
  • fds_skewed = ((fa*point)+(fb*right_1)+(fc*right_2)+(fd*right_3)+(fe*right_4))/((dx(i))^2);
  • Formula to calculate the 4th order approximations of the second order derivative by backward difference scheme (bds).
  • a=5/6, b=61/12, c=-13, d=107/6, e=-77/6
  • bds_skewed = ((ba*point)+(bb*left_1)+(bc*left_2)+(bd*left_3)+(be*left_4))/((dx(i))^2);

Main programe :-

clear all
close all
clc

% function of cds
ca=-1/12;
cb=+4/3;
cc=-5/2;
cd=+4/3;
ce=-1/12;

% function of fds
fa=+15/4;
fb=-77/6;
fc=+107/6;
fd=13;
fe=61/12;

% function of bds
ba=5/6;
bb=61/12;
bc=-13;
bd=107/6;
be=-77/6;

x = pi/4;
%analytical_function = exp(x)*cos(x)
%analytical_derivative = -2*exp(x)*sin(x);
%Assigning values for dx
dx = linspace(pi/40,pi/4000,100);

for i = 1:length(dx)
    analytical_derivative = -2*exp(x)*sin(x);
  
    left_4 = (exp(x-(4*dx(i))))*(cos(x-(4*dx(i))));
    left_3 = (exp(x-(3*dx(i))))*(cos(x-(3*dx(i))));
    left_2 = (exp(x-(2*dx(i))))*(cos(x-(2*dx(i))));
    left_1 = (exp(x-(dx(i))))*(cos(x-(dx(i))));
    point = (exp(x))*(cos(x));
    right_1 = (exp(x+(dx(i))))*(cos(x+(dx(i))));
    right_2 = (exp(x+(2*dx(i))))*(cos(x+(2*dx(i))));
    right_3 = (exp(x+(3*dx(i))))*(cos(x+(3*dx(i))));
    right_4 = (exp(x+(4*dx(i))))*(cos(x+(4*dx(i))));
    %Substituting the values in the derived formula
    cds_skewed = ((ca*left_2)+(cb*left_1)+(cc*point)+(cd*right_1)+(ce*right_2))/((dx(i))^2);
    fds_skewed = ((fa*point)+(fb*right_1)+(fc*right_2)+(fd*right_3)+(fe*right_4))/((dx(i))^2);
    bds_skewed = ((ba*point)+(bb*left_1)+(bc*left_2)+(bd*left_3)+(be*left_4))/((dx(i))^2);
  
    error_cds(i) = abs(cds_skewed-analytical_derivative);
    error_fds(i) = abs(fds_skewed-analytical_derivative);
    error_bds(i) = abs(bds_skewed-analytical_derivative);
end 

% plot 
figure(1)
loglog(dx,error_cds,'r','marker','*','linewidth',1);
hold on
loglog(dx,error_fds,'b','marker','square','linewidth',1);
hold on
loglog(dx,error_bds,'g','marker','diamond','linewidth',1);
grid on
xlabel('grid size');
ylabel('error');
legend('central differencing scheme','forward differencing scheme','backward differencing scheme','location','east');

Explanation for programe:-

  1. calculating the value from 'for' loop and error values and it calculate for skewed in right, left, centre difference skewed.
  2. To calculate error term use 'absolute' command.
  3. Then you have to plot the graph.
  4. Use 'loglog' command because the values we got are very small.
  5. Plot between dx and error terms .
  6. For fds and bds just you have to add formula and respective error terms in the programe and plot them with loglog command.
  7. Use legend command to mark the curves that you have been plotted.

Explanation for skewed scheme :-

  • Skewed differnces scheme is useful because it will work in everycondition of nodes availabiity but central difference schemes not work on the all nodes .
  • Right skewed are usesd for the information travel from the source to system like flow over aerofoil wings.
  • Left skewed are used when information travel from the system to source like in pumps,compressor etc .
  • Depening upon these type of situation skewed schemes will give more accuracy than central differencing schemes.

Result :-

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.