MATLAB: How do you change the romberg.m file so that it derives instead of integrates

romberg

I am trying to change the romberg.m file so that it derives a function, instead of integrate it. I was trying to change the 26th line (seen below) to grad instead of trap, but I am given a set of numbers and NOT a function, so that wouldn't work.
If anyone had an idea of how to either change the .m file so that it would derive, or if you knew how to make a set of data points into a function so that it can be used in the function that would be awesome.
I am pretty sure it is something as simple as changing trap to something else, but I can't figure it out.
Thank you in advance.
.m
function [q,ea,iter]=romberg(func,a,b,es,maxit,varargin)
% romberg: Romberg integration quadrature
% q = romberg(func,a,b,es,maxit,varargin):
% Romberg integration.
% input:
% func = name of function to be integrated
% a, b = integration limits
% es = desired relative error (default = 0.000001%)
% maxit = maximum allowable iterations (default = 30)
% p1,p2,... = additional parameters used by func
% output:
% q = integral estimate
% ea = approximate relative error (%)
% iter = number of iterations
if nargin<3,error('at least 3 input arguments required'),end
if nargin<4|isempty(es), es=0.000001;end
if nargin<5|isempty(maxit), maxit=50;end
n = 1;
I(1,1) = trap(func,a,b,n,varargin{:});
iter = 0;
while iter<maxit
iter = iter+1;
n = 2^iter;
I(iter+1,1) = trap(func,a,b,n,varargin{:});
for k = 2:iter+1
j = 2+iter-k;
I(j,k) = (4^(k-1)*I(j+1,k-1)-I(j,k-1))/(4^(k-1)-1);
end
ea = abs((I(1,iter+1)-I(2,iter))/I(1,iter+1))*100;
if ea<=es, break; end
end
q = I(1,iter+1);

Best Answer

I have a hard time imagining why you think it would be appropriate to change an integration tool to differentiate, especially an integration tool that expects to be passed a function handle and you want to switch to providing an array.
But to answer your specific question:
grad() is not a Mathworks routine. There are contributions in the File Exchange that provide a grad() routine, but you would need to examine them to see if they are suitable for your purpose.
The numeric gradient routine in MATLAB is named gradient(), which does operate given a numeric array.