Challenge

Week 3 - Taylor table method and Matlab code

x=pi/3;
dx=linspace(pi/20,pi/400,20);
exact_derivative= -2*exp(x)*sin(x);

Input of X is taken as pi/3 and value of dx is taken in range of 20 intervals from pi/20 to pi/400.

exact derivative of given expression is calculated.

for i=1:length(dx)
skewed_right_diffrencing=(3.75*exp(x)*cos(x)-12.833333333333333*exp(x+dx(i))*cos(x+dx(i))+17.8333333333333*exp(x+2*dx(i))*cos(x+2*dx(i))-13*exp(x+3*dx(i))*cos(x+3*dx(i))+5.08333333333333*exp(x+4*dx(i))*cos(x+4*dx(i))-0.83333333333*exp(x+5*dx(i))*cos(x+5*dx(i)))/dx(i)^2;
central_differencing=(-0.08333333333333333333*exp(x-2*dx(i))*cos(x-2*dx(i))+1.333333333333333333333*exp(x-dx(i))*cos(x-dx(i))-2.5*exp(x)*cos(x)+1.33333333333333333*exp(x+dx(i))*cos(x+dx(i))-0.083333333333333333333*exp(x+2*dx(i))*cos(x+2*dx(i)))/dx(i)^2;
skewed_left_diffrencing=(3.75*exp(x)*cos(x)-12.833333333333333*exp(x-dx(i))*cos(x-dx(i))+17.8333333333333*exp(x-2*dx(i))*cos(x-2*dx(i))-13*exp(x-3*dx(i))*cos(x-3*dx(i))+5.08333333333333*exp(x-4*dx(i))*cos(x-4*dx(i))-0.83333333333*exp(x-5*dx(i))*cos(x-5*dx(i)))/dx(i)^2;
skewed_right_error(i)=abs(exact_derivative-skewed_right_diffrencing);
central_error(i)=abs(exact_derivative-central_differencing);
skewed_left_error(i)=abs(exact_derivative-skewed_left_diffrencing);
end

for all values of 'dx' central _differencing, skewed_right_ddifferencing, skewed_left_differencing is calcullated whose equation for given expression is derived using Taylor's table. central_error is calculated by differencing exact and central_differencing. similarly skewed_left_derivative and skewed_right_derivative is calculated.

figure(1)
loglog(dx, central_error, 'r');
hold on
loglog(dx,skewed_right_error,'b');
loglog(dx,skewed_left_error,'g');
legend('central_error','skewed_right_error','skewed_left_error')
grid on;
title('comparison of errors for second order derivtive using fourth order approximation' )

central_error, skewed_left_differencing, Skewed_right_differencing is plotted.legend of error is calculated, 'comparison of errors for second order derivative using fourth order approximation' is title of graph.

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.