Challenge

Week 3.5 - Deriving 4th order approximation of a 2nd order derivative using Taylor Table method

Report is attached as a pdf

The graph obtained proves that skewed schemes are less accurate when compared to central schemes. But they have to be used at boundary conditions where we have points lying only on one side of the boundary. In this case a central scheme cannot be used. So, we have to go with skewed schemes depending on whether the boundary is left extreme or right extreme. For left extreme boudnary we go with right skewed scheme and for right extreme boundary we go with left skewed scheme

clear all;
clc;
% Assume x = 10
x = 10;

% Given Function:
% f(x) = exp(x) * cos(x)
% => f'(x) = -exp(x)*sin(x) + exp(x)*cos(x)
% => f''(x) = -exp(x)*cos(x) - exp(x)*sin(x)
%             -exp(x)*sin(x) + exp(x)*cos(x)
% => f''(x) = -2*exp(x)*sin(x)

% Analytical
analytical = -2*exp(x)*sin(x);
delta_x = 0.001;

A_central = [1 1 1 1 1; -2 -1 0 1 2; 2 1/2 0 1/2 2; -8/6 -1/6 0 1/6 8/6; 16/24 1/24 0 1/24 16/24];

A_skew = [1 1 1 1 1; 0 1 2 3 4; 0 1/2 4/2 9/2 16/2; 0 1/6 8/6 27/6 64/6; 0 1/24 16/24 81/24 256/24];

for i=1:100
    solution(i, 1) = delta_x;
    B = [0; 0; 1/(delta_x)^2; 0; 0];

    % Central Scheme
    central = inv(A_central)*B;
    solution(i,2) = central(1)*exp(x - 2*delta_x)*cos(x - 2*delta_x)  +  central(2)*exp(x - 1*delta_x)*cos(x - 1*delta_x)  +  central(3)*exp(x + 0*delta_x)*cos(x + 0*delta_x) + central(4)*exp(x + 1*delta_x)*cos(x + 1*delta_x) + central(5)*exp(x + 2*delta_x)*cos(x + 2*delta_x);

    % Skewed Scheme
    skew = inv(A_skew)*B;
    solution(i,3) = skew(1)*exp(x + 0*delta_x)*cos(x + 0*delta_x)  +  skew(2)*exp(x + 1*delta_x)*cos(x + 1*delta_x)  +  skew(3)*exp(x + 2*delta_x)*cos(x + 2*delta_x) + skew(4)*exp(x + 3*delta_x)*cos(x + 3*delta_x) + skew(5)*exp(x + 4*delta_x)*cos(x + 4*delta_x);

    % Change delta_x value
    delta_x += 0.0015;
end
plot(solution(:, 1), abs(solution(:, 2) - analytical),'LineWidth', 2, solution(:, 1), abs(solution(:, 3) - analytical), 'LineWidth', 2)
xlabel('\Delta x')
ylabel('Absolute Error')
title('Absolute Error between analytical solution and numerical solutions')
legend('Central Scheme', 'Skewed Scheme','location', 'NorthWest')
xlim([0, 0.15])
ylim([0, 15])
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.