Project

Approximation Error curves

As it can be seen from the logarithmic graph plot, the curve of the first order error decreases slowly, from right to left, as compared to second order error curve. And fourth order error curve decreases more quickly than both first order error and second order error.

This shows that as the value of dx decreases the difference between the exact and approximate value of the first derivative also decreases. But, this process is more rapid in fourth order approximation, slightly less in the second-order approximation, and least in first order approximation.

Logarithmic plot

\"Approximation

close all
clear all
clc

% given conditions 
x = pi/3;

% assume range of dx
dx = linspace(pi/4,pi/4000,20);

% given F(x) = sin(x)/x^3
% first derivative F\'(x) = (cos(x)*x^3 - 3*x^2*sin(x))/x^6

analytical_derivative = (cos(x)*x^3 - 3*x^2*sin(x))/x^6;
 
for i = 1:length(dx)
   % first order approximation error
   first_order_approx(i) = (sin(x+dx(i))/(x+dx(i))^3 - sin(x)/x^3)/dx(i);

   % second order approximation error
   second_order_approx(i) = (sin(x+dx(i))/(x+dx(i))^3 - sin(x-dx(i))/(x-dx(i))^3)/(2*dx(i));

% fourth order approximation error
j_1 = sin(x-2*dx(i))/(x-2*dx(i))^3;
j_2 = sin(x-dx(i))/(x-dx(i))^3;
j_3 = sin(x+dx(i))/(x+dx(i))^3;
j_4 = sin(x+2*dx(i))/(x+2*dx(i))^3;

fourth_order_approx(i) = (j_1 - 8*j_2 + 8*j_3 - j_4)/(12*dx(i));

first_order_error(i) = abs(first_order_approx(i) - analytical_derivative);
second_order_error(i) = abs(second_order_approx(i) - analytical_derivative);
fourth_order_error(i) = abs(fourth_order_approx(i) - analytical_derivative);

end

figure(1)
plot(dx,first_order_error,dx,second_order_error,\'m\',dx,fourth_order_error,\'k\')
xlabel(\'dx\')
ylabel(\'error\')
legend(\'first order error\',\'second order error\',\'fourth order error\')
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.