source: MML/trunk/machine/SOLEIL/common/toolbox/gaussquad/rombquad.m @ 17

Last change on this file since 17 was 17, checked in by zhangj, 10 years ago

To have a stable version on the server.

  • Property svn:executable set to *
File size: 1.3 KB
Line 
1function anss = rombquad(f,a,b,m)
2%ROMBQUAD(f,a,b,m) evaluates the integral of f from a to b.
3% f is an inline function or function handle.
4% a is the lower limit of integration.
5% b is the upper limit of integration.
6% m - is the exponent in the relative error.  For example m = 10 implies an
7% estimated relative error of 1e-10.
8%
9% Example: 
10%
11%           f = @(x) x.^2; % Vectoized function handle.
12%           rombquad(f,0,2); % The integral from 0 to 2.
13%
14% See also quad, quadl, quadv and gaussquad (on the FEX)
15%
16% Author:  Matt Fig
17% Contact:  popkenai@yahoo.com
18 
19if nargin<3
20   error ('Not enough arguments. See help.')
21elseif nargin<4 || floor(m)~=m || m <1
22    m = 10;
23end
24
25if isinf(a) || isinf(b)
26   error('Infinite limits not allowed.')
27end
28
29h = 2.^((1:m)-1)*(b-a)/2^(m-1);             % These are the intervals used.
30k1 = 2.^((m-2):-1:-1)*2+1;                  % Index into the intervals.
31f1 = feval(f,a:h(1):b);                     % Function evaluations.
32R = zeros(1,m);                             % Pre-allocation.
33% Define the starting vector:
34for ii = 1:m
35        R(ii) = 0.5*h(ii)*(f1(1)+2*...
36            sum(f1(k1(end-ii+1):k1(end-ii+1)-1:end-1)) + f1(end));
37end
38% Interpolations:
39for jj = 2:m
40    jpower = (4^(jj-1)-1);
41    for kk = 1:(m-jj+1)
42        R(kk) = R(kk)+(R(kk)-R(kk+1))/jpower;
43    end
44end
45anss = R(1);
Note: See TracBrowser for help on using the repository browser.