%Finite Centered Difference min: This m-file will compute the compare the %maximum accuracy obtainable with the finite centered difference to the %maximum accuracy obtainable with the finite forward difference for there %respective values of hmin h=10.^(-20:.01:1); %given h-values fc_deriv_approx=[(1+h).^5-(1-h).^5]./(2.*h); %finite centered derivative for each value of h ff_deriv_approx=[(1+h).^5-(1).^5]./h; %finite forward derivative for each value of h fc_difference=fc_deriv_approx-5; %difference between finite centered difference and true value ff_difference=ff_deriv_approx-5; %difference between finite forward difference and true value abs_fc_difference=abs(fc_difference); %need absolute value or else we'll get -5 for h=0. abs_ff_difference=abs(ff_difference); [C1,I1]=min(abs_fc_difference) %find minimum error/maximum accuracy for each case [C2,I2]=min(abs_ff_difference) %and index at which it occurs for each I1 h(I1) I2 h(I2)