Week 3 - Taylor table method and Matlab code
First of all we are going to look up for the calculation of fourth order approximation of various schemes and we are going to prove that our skewed schemes are fourth-order accurate.
Before that, skewed schemes are useful when compared to central difference, because the number of nodes in skewed schemes are greater than the number of nodes in central difference scheme.
Higher the number of nodes higher the value of accuracy we can achieve.
1) Central difference:
page1
page2
calculation explanation:
Here we are calculating the values using central difference scheme.
Also we are evaluating the variables of the second order derivative equation.
Then, we are creating a taylor table for the equation.
2)Skewed right-sided difference:
page1
page2
page3
calculation explanation:
Here we are calculating the values using Skew right side scheme.
Also we are evaluating the variables of the second order derivative equation.
Then, we are creating a taylor table for the equation.
3)Skewed left-sided difference:
page1
page2
page3
calculation explanation:
Here we are calculating the values using Skew left side scheme.
Also we are evaluating the variables of the second order derivative equation.
Then, we are creating a taylor table for the equation.
Equations of approximation and analytical derivative are shown below,
In the above mentioned image, I have given the equations which we are going to use in the main program to solve the problem.
The main program that compares the error values of various schemes of fourth order of second order derivative is shown below,
clear all
close all
clc
x=pi/3;
dx = linspace(pi/4,pi/400,20);
for i = 1:length(dx)
rightskew_error(i)=rightskew_approximation(x,dx(i));
leftskew_error(i)=leftskew_approximation(x,dx(i));
centraldiff_error(i)=centraldiff_approximation(x,dx(i));
end
loglog(dx,rightskew_error,'g-+')
hold on
loglog(dx,leftskew_error,'b-*')
loglog(dx,centraldiff_error,'r-o')
xlabel('values of dx')
ylabel('errors')
legend('rightskew','leftskew','centraldiff')
CODE EXPLANATION:
1)Here we are providing x=pi/3 and also we are giving values for dx using linsapce command.
2)Then, we are creating a for loop for the various schemes of 4th order approximation,to compute the function.
3)Then, we are printing a graph to view the results and to compare the error values of various schemes of fourth order approximations.
4)Also we are providing markers to the plot to point the values of errors.
To ease the process of comparing the approximations of various schemes I have created four function files in which we will include the formula for various approximations,
CODE EXPLANATION:
Here we are creating a funtion file in which we assing the equation for the main funtion to solve the program.
The function files of various schemes of approximations are shown below,
1)Central Difference Approximation:
CODE EXPLANATION:
Here we are creating a function to compute the Central Difference approximation and also we are also funtioning out the error value for the function.
2)Right Skew Approximation:
CODE EXPLANATION:
Here we are creating a function to compute the Right Skew approximation and also we are also funtioning out the error value for the function.
3)Left Skew Approximation:
CODE EXPLANATION:
Here we are creating a function to compute the Left Skew approximation and also we are also funtioning out the error value for the function.
The results are plotted in a graph and is shown below,