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'),endif nargin<4|isempty(es), es=0.000001;endif nargin<5|isempty(maxit), maxit=50;endn = 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