Week 3.5 - Deriving 4th order approximation of a 2nd order derivative using Taylor Table method
Deriving 4th order approximation of a 2nd order derivative using Taylor approximation
Derive the following 4th order approximations of the second-order derivative.
1. Central difference
The approximatin will be of the form
f"(x)=(approximate) {a f(x-2h)+b f(x-h)+c f(x)+d f(x+h)+e f(x+2h)}/h^2
Constants are found in the code using A\b
a = -0.083333, b = 1.3333, c = -2.5000, d = 1.3333, e = -0.083333
order of accuracy =5-2+1=4
where 5 nodes in the stensil are use and order of derivative is 2
2. Skewed right-sided difference
f"(x)=(approximate) {a f(x)+b f(x+h)+c f(x+2h) +d f(x+3h) +e f(x+4h)+g f(x+5h)}/h^2
Constants are
a = 3.7500, b = -12.833, c = 17.833, d = -13.000, e = 5.0833, g = -0.8333
order of accuracy =6-2=4
where 6 nodes in the stensil are use and order of derivative is 2
3. Skewed left-sided difference
f"(x)=(approximate) {a f(x)+b f(x-h)+c f(x-2h) +d f(x-3h) +e f(x-4h)+g f(x-5h)}/h^2
constants are
a = 3.7500, b = -12.833, c = 17.833, d = -13.000, e = 5.0833, g = -0.8333
order of accuracy =6-2=4
where 6 nodes in the stensil are use and order of derivative is 2
Objective
To write a matlab/octave program that uses Tylor series approximation of order 4 to solve a second order derivate. The program must use central approximation, skew left and right aproximation and compare all three of them.
The function for finding the derivative is f(x)=exp(x) cos(x)
Solution Procedure
for the solution i have used a total of 5 files, including a main script which along with all the other 4 files.
I will explain each files seperately
The first file is the main_script.m file, which we run to get the desired result. In this script x and dx are defined and also an analytical derivative is calculated.
Then we go with numerical derivative, in this part of the code three functions are called in order first central_second_derivative(x,dx) from the file central_second_derivative.m then left_skewed_second_derivative(x,dx) from the file left_skewed_second_derivative.m and last right_skewed_second_derivative(x,dx) form the file right_skewed_second_derivative.m
All the three functions mentioned above performs the same algorithm, all of the functions takes two inputs x and h (step size), and returns the numerical derivative according to the scheme. Inside each function there are two matrixed corresponding to the appropriate scheme and upon completion of the linear algebra operation, numerical derivate is caluclated.
Now the result is obtained inside the main_script.m file. This result is compared with the analytical derivative and a bar plot is plotted
Result
A bar plot is plotted comparing schemes with error of the schemes, it is observed that the central difference approximation has the least error and skewed right side has the highest error.
These are the result after running the program.
y_analytical = 284.63
y_2_central = 284.68
y_2_left = 286.69
y_2_right = 288.62
error_central = 0.049249
error_left = 2.0549
error_right = 3.9838
Discussion
The program help to understand how numerical mehtods work in finding the second derivative and also how to evaluate error. And to exploit various schemes and compare them and also to understand where these scheme are most appropriate.
In your own words, describe why a skewed scheme is useful? What can a skewed scheme do that a CD scheme cannot?
Central Difference scheme has the least error, this is what our program results are suggesting. Even though CD is more accurate its use is limited to the inside grid of a domain, when CD scheme is used in the boundary we need to assume points which makes more error. So for this purpose a Skew Scheme is most appropriate, becasue skew scheme doesnt need to assume any points outside the boudary.