Project

Effect of dx on errors of different approximations

Fourth_order_approx program code

function out = fourth_order_approx(x,dx);
analytical_derivative=((x^3*cos(x))-(sin(x)*3*x^2))/x^6;
fourth_order_equation=((sin(x-2*dx)/(x-2*dx)^3)-(8*sin(x-dx)/(x-dx)^3)+(8*sin(x+dx)/(x+dx)^3)-(sin(x+2*dx)/(x+2*dx)^3))/(12*dx)
out=abs(fourth_order_equation-analytical_derivative);
end​

Second_order_approx program code

function out = second_order_approx(x,dx);
analytical_derivative=((x^3*cos(x))-(sin(x)*3*x^2))/x^6;
second_order_equation=(((sin(x+dx))/((x+dx)^3))-((sin(x-dx))/(x-dx)^3))/(2*dx);
out=abs(second_order_equation-analytical_derivative);
end​

First_order_approx program code

function out = first_order_approx(x,dx);
analytical_derivative=((x^3*cos(x))-(sin(x)*3*x^2))/x^6;
first_order_equation=(((sin(x+dx))/((x+dx)^3))-((sin(x)/x^3)))/(dx)
out=abs(first_order_equation-analytical_derivative);
end​

Sample code for effect of dx or error

close all
clear all
clc
dx=linspace(1/40,1/400,30);
x=pi/3;
for j = 1:length(dx)
  first_order_error(j) =first_order_approx(x,dx(j));
  second_order_error(j)=second_order_approx(x,dx(j));
  fourth_order_error(j)=fourth_order_approx(x,dx(j));
  end
plot(dx,fourth_order_error);
xlabel(\'dx\');
ylabel(\'fourth order error values\');
title(\'dx Vs fourth order error\');  

​

Sample output

\"Sample

Fourth order error

\"Fourth_order_error\"

Second order error

\"Second_order_error\"

First order error

\"First_order_error\"

Comparison between graphs:

For first order error, the graph increases linearly with increase in size of dx. For second order error the magnitude of slope of reduction of error with decerease in size of dx is higher compared to that of first order error. This magnitude is even greater for fourth order error when compared to second order error. Thus fourth order approximations are more accurate when compared to third order approximation which is better when compared to first order approximations

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.