Challenge

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

Using Central differencing method:

The stencil will look like this: ….(i-2)….(i-1)….(i)….(i+1)…..(i+2)

Equation from above stencil: δu^2/δx^2 = af(i − 2) + bf(i − 1) + cf(i) + df(i + 1) + ef(i +2)

Taylors Table :

f(i) △xf(i) △x^2f''(i) △x^3f'''(i) △x^4f''''(i) △x^5f'''''(i) △x^6f'''''(i)
f(i-2) a -2a 4a/2 -8a/6 16a/4 -32a/120 64a/240
f(i-1) b -b b/2 -b/6 b/24 -b/120 b/240

f(i)

c 0 0 0 0 0 0
f(i+1) d d d/2 d/6 d/24 d/120 d/240
f(i+2) e 2e 4e/2 8e/6 16e/24 -32e/120 64e/120
af(i − 2) + bf(i − 1) + cf(i) + df(i + 1) + ef(i +2) 0 0 1 0 0 ? ?

a=-020833 b=1.33 c=-2.500 d=1.33 e=-0.08333

using skewed right difference:

f(i) △xf(i) △x^2f''(i) △x^3f'''(i) △x^4f''''(i) △x^5f'''''(i) △x^6f'''''(i)

f(i)

a 0 0 0 0 0 0

f(i+1)

b b b/2 b/6 b/24 b/120 b/720
f(i+2) c 2c 4c/2 8c/2 16c/24 32c/120 64c/720
f(i+3) d 3d 9d/2 27d/6 81d/24 243d/120 729d/720
f(i+4) e 4e 16e/2 64e/6 256e/24 1024e/120 4096e/720
f(i+5) g 5g 25g/2 125g/6 625g/24 3125g/120 15625g/720
sum 0 0 1 0 0 0 ?

a = 3.75 b=-12.8333 c=17.833 d=-13.00 e=5.0833 g=-0.833

using skewed left-sided difference:

f(i) △xf(i) △x^2f''(i) △x^3f'''(i) △x^4f''''(i) △x^5f'''''(i) △x^6f'''''(i)
f(i-5) a -5a 25a/2 -125a/6 625a/24 -3125a/120 15625a/720
f(i-4) b -4b 8b -64b/6 256b/24 -1024b/120 4096b/720
f(i-3) c -3c 9c/2 -27c/6 81c/24 -243c/120 729c/120
f(i-2) d -2d 2d -8d/6 16d/24 -32d/120 64d/720
f(i-1) e -e e/2 -e/6 e/24 -e/120 e/720
f(i) g 0 0 0 0 0 0
sum 0 0 1 0 0 0 ?

we get a=0.8333 b=5.0833 c=-13.00 d=17.8333 e=-12.83333 g=3.7500

% 4th order centraldiffrence
function error_central_differencing = central difference (x, dx)

% Analytical function f(x) = exp(x)*cos(x)

% f''(x) = -2*exp(x)*sin(x);
analytical derivative = -2*exp(x)*sin(x);

%  Taylor table;
a=-0.083333;
b=1.333333;
c=-2.500000; 
d=1.333333;
e=0.083333;

central_differencing_fourth_order_approx= ((a*exp(x-2 dx) cos(x-2 dx))+(b*exp(x-dx) cos(x-dx))+(c exp(x) cos(x))+(d*exp(x+dx) *cos(x+dx))+(e*exp(x+2*dx) *cos(x+2*dx)))/dx^2;
error_central_differencing_differencing = abs(central_differencing_fourth_order_approx - analytical_derivative);
end
%right_skewed_difference

function error_skewed_right_sided=skewed_right_sided(x,dx)

% analytical function f(x)=exp(x) *cos(x);

% %f''(x)=-2*exp(x)*sin(x);
analytical derivative=-2*exp(x)*sin(x);

%values of coefficients calculated from our Taylor table;
a=3.75000;
b=-12.83333;
c=17.83333;
d=-13.00000;
e=5.08333;
g=-8.83333;


%skewed right-sided differencing=((a f(x))+(b*f(x+dx))+(c f(x+2*dx))+(d*f(x+3*dx))+(e*f(x+4*dx))+(g*f(x+5*dx)))/dx^2;

skewed_right_sided_fourth_order_approx=((a*exp(x)*cos(x))+(b*exp(x+dx) * cos(x+dx))+(c*exp(x+2*dx) * cos(x+2*dx))+ (d*exp(x+3 dx) *cos(x+3*dx))+(e*exp(x+4 dx) *cos(x+4*dx))+(g*exp(x+5*dx) * cos(x+5*dx)))/dx^2;

error_skewed_right_sided=abs(skewed_right_sided_fourth_order_approx-analytical_derivative);
end
%skewed left diffrence

function error_skewed_left_sided=skewed_left_sided(x, dx)

% analytical function f(x)=exp(x)*cos(x); 

% %f''(x)=-2*exp(x)*sin(x);
analytical derivative=-2*exp(x)*sin(x);

%values of coefficients calculated from our Taylor table;
a=-0.83333;
b=5.08333;
c=-13.00000;
d=17.83333;
e=-12.83333;
g=3.75000;



%skewed left-sided differencing=((a f(x-5*dx))+(b*f(x-4*dx))+(c f(x-3 dx))+(d f(x-2 dx))+(e f(x-dx))+(g*f(x)))/dx^2;
% %skewed left-sided fourth order approximation;

skewed_left_sided_fourth_order_approx=((a*exp(x-5*dx)*cos(x-5*dx))+(b*exp(x-4*dx)*cos(x-4*dx))+(c*exp(x-3*dx)*cos(x-3*dx))+(d*exp(x-2* dx) * cos(x-2*dx))+(e*exp(x-dx) *cos(x-dx))+(g*exp(x) *cos(x)))/dx^2;

error_skewed_left_sided=abs(skewed_left_sided_fourth_order_approx-analytical_derivative);
end

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.