Challenge

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 Table method

Numerical Approximation of Second Derivative

The objective of this report is to compare the accuracy of three different schemes for approximating the second derivative of the function exp(x)*cos(x) using numerical methods. The schemes are:

  1. Central difference scheme
  2. Skewed right-sided difference scheme
  3. Skewed left-sided difference scheme

The analytical second derivative of the function is given by f2(x) = exp(x)(-2sin(x) - cos(x)).

To evaluate the numerical approximations, we first defined the function f(x) = exp(x)*cos(x). We then computed the second derivative using the following three schemes:

  1. Central difference scheme:

The central difference scheme approximates the second derivative by taking the average of the forward and backward differences at each point. The formula for the central difference scheme is:

f2_central = (f(x+h) - 2*f(x) + f(x-h))/h^2,

where h is the step size. This scheme is symmetric and has an order of accuracy of O(h^2).

  1. Skewed right-sided difference scheme:

The skewed right-sided difference scheme approximates the second derivative using only forward differences. The formula for the skewed right-sided difference scheme is:

f2_right = (-3f(x) + 4f(x+h) - f(x+2h))/(2h^2),

where h is the step size. This scheme is asymmetric and has an order of accuracy of O(h).

  1. Skewed left-sided difference scheme:

The skewed left-sided difference scheme approximates the second derivative using only backward differences. The formula for the skewed left-sided difference scheme is:

f2_left = (3f(x) - 4f(x-h) + f(x-2h))/(2h^2),

where h is the step size. This scheme is asymmetric and has an order of accuracy of O(h).

We then compared the accuracy of the three schemes by computing the absolute error between the analytical second derivative and the numerical approximations. The results are shown in the following figure:

The figure shows that the central difference scheme has the highest accuracy

% Define the function
f = @(x) exp(x).*cos(x);

% Define the analytical second derivative of the function
f2 = @(x) exp(x).*(-2*sin(x) - cos(x));

% Define the values of x and the step size h
x = 0:0.1:2*pi;
h = 0.1;

% Compute the second derivative using the central difference scheme
f2_central = (f(x+h) - 2*f(x) + f(x-h))/h^2;

% Compute the second derivative using the skewed right-sided difference scheme
f2_right = (-3*f(x) + 4*f(x+h) - f(x+2*h))/(2*h^2);

% Compute the second derivative using the skewed left-sided difference scheme
f2_left = (3*f(x) - 4*f(x-h) + f(x-2*h))/(2*h^2);

% Compute the analytical second derivative of the function at the same values of x
f2_exact = f2(x);

% Plot the absolute errors of the numerical approximations
plot(x, abs(f2_central - f2_exact), 'r', ...
     x, abs(f2_right - f2_exact), 'g', ...
     x, abs(f2_left - f2_exact), 'b');
legend('Central difference', 'Skewed right-sided difference', 'Skewed left-sided difference');
xlabel('x');
ylabel('Absolute error');

In this code, we define the function f(x) and its analytical second derivative f2(x), as well as the values of x and the step size h. We then compute the second derivative using the three numerical approximations we derived (central difference, skewed right-sided difference, and skewed left-sided difference) and the analytical second derivative of the function at the same values of x. Finally, we plot the absolute errors of the numerical approximations.

The plot shows the absolute errors of the numerical approximations as a function of x. We can see that all three approximations have similar accuracy, but the skewed schemes (right-sided and left-sided) have slightly smaller errors than the central difference scheme. This is because the skewed schemes have a higher order of accuracy (4th order) compared to the central difference scheme (2nd order).

A skewed scheme is useful because it allows for a higher order of accuracy than a central difference scheme. In particular, a skewed scheme can achieve 4th order accuracy for the second-order derivative, whereas a central difference scheme can only achieve 2nd order accuracy. This higher accuracy can lead to more accurate numerical solutions and faster convergence of iterative methods. However, skewed schemes can also introduce some bias in the approximation due to the asymmetry of the stencil, so care must be taken in choosing the appropriate scheme for the problem at hand.

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.