Project

Taylor table to calculate third order approximation of second order derivative by using central difference and skewed stencil approach with Matlab programming

Problem statement:

Derive the following third 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 third-order approximation .

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.

a. Provide a plot that compares the absolute error between the above-mentioned schemes

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

Solution formulation:

here this higher order derivatives are computed with taylor series and to get third order approximation i have ensure to collect data from five points through five linked equation and then solved it to compute those coefficient and then i have added those results in below code.

here as we are considering derivatives of fourth order and thus this method is providing fifth order approximation of second order derivative as we are lruncating fifth power of step size during taylor series expansion and finally devided by h^2 we get h^3 means we are approximating our second order derivative after 3rd power and thus it is called as third order approximation of second order derivative.

Matlab code:

clc;
clear all;
close all;
x=pi/3;
h=0.1;
analytical_derivative=-2*exp(x)*sin(x);
AD=analytical_derivative
f1=exp(x-4*h)*cos(x-4*h);
f2=exp(x-3*h)*cos(x-3*h);
f3=exp(x-2*h)*cos(x-2*h);
f4=exp(x-h)*cos(x-h);
f5=exp(x)*cos(x);
f6=exp(x+h)*cos(x+h);
f7=exp(x+2*h)*cos(x+2*h);
f8=exp(x+3*h)*cos(x+3*h);
f9=exp(x+4*h)*cos(x+4*h);
%here by central difference formula
CD=(-.0416*(f3+f7)+0.6666*(f4+f6)-1.25*f5)/(0.5*h^2);
%left hand skewed formula
LSM=(0.45833*f1-2.3333*f2+4.75*f3-4.3333*f4+1.45833*f5)/(0.5*h^2);
%right hand skewed formula
RSM=(1.45833*f5-4.3333*f6+4.75*f7-2.333*f8+.45833*f9)/(0.5*h^2);
Error(1)=abs(CD-AD)
Error(2)=abs(LSM-AD)
Error(3)=abs(RSM-AD)

a=categorical({\'central difference\',\'left hand skewed formula\',\'right hand skewed formula\'});
bar(a,Error)

Output:

1) To compare error from central difference and skewwed formula as follows and it is observed that central difference scheme find more accurate over left and right skewwed formula.

2) But for central difference formula we need data from both side of given point and that is only weak point with this methood whereas skewed formula allows one to use data points on either any of side of that point and that is easy to solve explicitly in CFD discretization but from accuracy point view we can say that central difference formula with matrix formulation by implicit approach would give better results.

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.