Project

Compute Fourth Order approximations for Second Order Derivative of a function using Central Difference and Skewed Right and Left Side Schemes

Using Taylors table, the following 4th order approximations of the second order derivative have been obtained:

1) Central difference

a(fi-2)+b(fi-1)+c(fi)+d(fi+1)+e(fi+2) where;

a=-0.0833; b=1.333; c=-2.5; d=1.333; e=-0.0833

2) Skewed right sided difference

a(fi)+b(fi+1)+c(fi+2)+d(fi+3)+e(fi+4) where;

a=2.9167; b=-8.667; c=9.5; d=-4.667; e=0.9167

3) Skewed left side difference

a(fi)+b(fi-1)+c(fi-2)+d(fi-3)+e(fi-4) where;

a=2.9167; b=-8.667; c=9.5; d=-4.667; e=0.9167

A skewed scheme is useful because, the coefficient of term x^3 is not zero. Thus, the number of terms in the series increases. With central difference, we consider only upto the term x^2, but with skewed approach we consider x^3 term as well. Thus accuracy of skewed is higher than that of central difference method. Also, skewed method requires information only from one side, unlike central difference scheme which requires information from both sides. This means that skewed scheme can be employed when we know the direction of information flow. Example of this would be fluid flow in a pipe where direction of fluid flow is known or heat flow condition where direction of heat flow is already known.

x=pi/3;
 n=1000;
dx=linspace(pi/3,pi/3000,n);  
analytical_solution = -2*sin(x)*exp(x);
for i=1:n
    fourth_order_approximate_solution_CDS(i) = ((-0.0833)*f_x(x-(2*dx(i)))) + ((1.333)*f_x(x-dx(i))) + (-2.5*f_x(x)) + (1.333*f_x(x+dx(i))) + ((-0.0833)*f_x(x+(2*dx(i))));
    fourth_order_approximate_solution_SRSD(i) =(2.9167*f_x(x)) +((-8.667)*f_x(x+dx(i)))+(9.5*f_x(x+(2*dx(i))))+((-4.667)*(f_x(x+(3*dx(i)))))+(0.9167*(f_x(x+(4*dx(i)))));
    fourth_order_approximate_solution_SLSD(i) = (2.9167*f_x(x)) +(-8.667*f_x(x-dx(i)))+(9.5*f_x(x-(2*dx(i))))+(-4.667*(f_x(x-(3*dx(i)))))+(0.9167*(f_x(x-(4*dx(i)))));
    error1(i) = abs(fourth_order_approximate_solution_CDS(i) - analytical_solution);
    error2(i) = abs(fourth_order_approximate_solution_SRSD(i) - analytical_solution);
    error3(i) = abs(fourth_order_approximate_solution_SLSD(i) - analytical_solution);
    fwd_diff(i) = (f_x(x+dx(i))-f_x(x))/dx(i);
    bwd_diff(i)  = (f_x(x)-f_x(x-dx(i)))/dx(i);
    error4(i) = abs(fwd_diff(i)-analytical_solution);
    error5(i) = abs(bwd_diff(i)-analytical_solution);
end

%Plots

loglog(dx,error1,\'--\');
hold on
loglog(dx,error2);
hold on
loglog(dx,error3);

legend(\'Central Difference\',\'Skewed Right Side\',\'Skewed Left Side\');
xlabel(\'dx\');
ylabel(\'Error\');
title(\'Error Comparison\')

Code for function used:

function out = f_x(x)
out = (cos(x)*exp(x));
end

Plots:

1) Comparison between CDS, SRSD, SLSDn

\"\"

As can be seen from the graph, central difference scheme has a higher error value as compred to skewed right and left side approaches. However, as value of dx decreases, the error difference between the schemes goes on reducing and becomes almost the same at low dx values. Higher accuracy of skewed approach is on account of using higher number of terms in the series.

2) Comparison between with FDS and BDS

\"\"

FDS and BDS are first order approximation schemes and thus tend to give much higher error as compared to fourth order schemes which can be clearly seen from the above graphs.

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.