Derivation of Fourth order approximations of second order derivative
%fourth order approxamataons
% f(x) = exp(x)*cos(x)
% f\'(x) = -2 * exp(x) * san(x)
clear all
close all
clc
x=pi/3
dx = pi/400
analytical_derivative = (-2) * exp(x) * sin(x)
central_difference = ((-0.833*exp(x-(2*dx))*cos(x-(2*dx)))+(1.333*exp(x-dx)*cos(x-dx))-(2.50*exp(x)*cos(x))+(1.333*exp(x+dx)*cos(x+dx))-(0.833*exp(x+(2*dx))*cos(x+(2*dx))))/(dx^2)
skewed_right_sided_difference = ((3.75* exp(x)*cos(x)-(12.833*exp(x+dx)*cos(x+dx))+(17.833*exp(x+(2*dx))*cos(x+(2*dx)))-(13*exp(x+(3*dx))*cos(x+(3*dx)))+(5.083*exp(x+(4*dx))*cos(x+(4*dx)))-(0.0833*exp(x+(5*dx))*cos(x+(5*dx)))))/(dx^2)
Skewed_left_sided_difference = ((3.75* exp(x)*cos(x) - (12.833*exp(x+dx)*cos(x+dx))+(17.833*exp(x+(2*dx))*cos(x+(2*dx)))-(13*exp(x+(3*dx))*cos(x+(3*dx)))+(5.083*exp(x+(4*dx))*cos(x+(4*dx)))-(0.0833*exp(x+(5*dx))*cos(x+(5*dx)))))/(dx^2)
forward_difference = ((exp(x+dx)*cos(x+dx))-(exp(x)*cos(x)))/dx
backward_difference = ((exp(x)*cos(x))-((exp(x-dx)*cos(x-dx))))/dx
central_error = abs(analytical_derivative-central_difference)
right_error = abs(analytical_derivative-skewed_right_sided_difference)
left_error = abs(analytical_derivative-Skewed_left_sided_difference)
forward_error = abs(analytical_derivative-forward_difference)
backward_error = abs(analytical_derivative-backward_difference)
y= [central_error, right_error,left_error];
figure(1)
width = 0.4;
barh(y,width)
title(\'comparision of higher approximation errors\')
xlabel(\'dx\')
ylabel(\'error_values\')
Derivation of Fourth order approximations of second order derivative:
Given f(x) = exp(x)*cos(x)
Fourth order approximations of second order derivative can be derived using Taylor Table method as below
a,b,c,d,e,f values are calculated using MATLAB. Below code demonstrates how these values can be calculated in MATLAB
Skewed_Left_scheme
a =[1 1 1 1 1 1; 0 -1 -2 -3 -4 -5; 0 1/2 2 9/2 8 25/2; 0 -1/6 -4/3 -9/2 -32/3 -125/6; 0 1/24 2/3 27/8 32/3 625/24; 0 -1/120 -4/15 -81/40 -128/15 -625/24]
b = [0; 0; 1; 0; 0; 0]
x = inv(a)*b
In the MATLAB code is written for evaluating the above results.
The output for the code is as follows:
The below graph can be plotted using the results
Graph represents 1.central_error, 2.right_error, 3.left_error.
X axis = dx
Y axis = error values
From the graph we can conclude that skewed right and skewed left approximations are equal. Central approximation error is more accurate compared with the other two.
* Skewed schemes are better compared to CDS, FDS, and BDS because they can give results irrespective of no of points. They even don\'t depend on the postion of points taken into consideration for calculation. Coming to CDS though it is accurate it requires symmetry of points both sides. Where as in Skewed schemes symmetry of points are not required.