%This code approximates the first derivative of a univariate valued
%function. It requires as inputs the function handle and the point for
%which the derivative is to be approximated at. Written by Philip Shaw,
%Fordham University, 2018.
function[DCD]=CDDer(fx,xbar)
hstar=eps^(1/3); %choose value of h based upon Heer and Maussner machine epsilon
fxbarph=fx(xbar+hstar); %function evaluated at point xbar plus h
fxbarmh=fx(xbar-hstar); %function evaluated at point xbar minus h
DCD=(fxbarph-fxbarmh)/(2*hstar); %central difference estimate for the derivative