function Q = adaptstp (f, a, b, fa, fm, fb, is, trace, varargin) %ADAPTSTP Recursive function used by ADAPT. % % Q = ADAPTSTP('F',A,B,FA,FM,FB,IS,TRACE) tries to % approximate the integral of f(x) from a to b to within a % relative error of IS/int(..)*eps. F is a string containing % the name of f. The remaining arguments are generated by adapt % or by the recursion. % % See also ADAPT. % Author: Walter Gander, 05/20/97 m = (a + b)/2; h = (b - a)/4; x = [a + h, b - h]; y = feval(f, x, varargin{:}); fml = y(1); fmr = y(2); i1 = h/1.5 * (fa + 4*fm + fb); i2 = h/3 * (fa + 4*(fml + fmr) + 2*fm + fb); i1 = (16*i2 - i1)/15; if (is + (i1-i2) == is), Q = i1; if (trace), disp([a b-a Q]), end; else Q = adaptstp (f, a, m, fa, fml, fm, is, trace, varargin{:}) + ... adaptstp (f, m, b, fm, fmr, fb, is, trace, varargin{:}); end;