代码拉取完成,页面将自动刷新
同步操作将从 NUDTexplorer/OptimTraj 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
function [x, err] = rombergQuadrature(fun,tSpan,tol)
% [x, err] = rombergQuadrature(fun,tSpan,tol)
%
% Compute the integral(fun), over the domain tSpan, to an accuracy of tol,
% using Romberg quadrature. Fully vectorized.
%
% Good for high-accuracy quadrature over smooth vector functions.
%
% If necessary, this function will automatically sub-divide the interval to
% achieve the desired accuracy. This should only occur when fun is stiff or
% non-smooth.
%
% INPUTS:
% fun = vector function to be integrated
% dx = fun(t)
% t = [1, nt] = time vector
% dx = [nx, nt] = function value at each point in t
% tSpan = [tLow, tUpp] = time span (domain) for integration
% tol = [nx,1] = desired error tolerance along each dimension
%
% OUTPUT:
% x = [nx,1] = integral along each dimension
% err = [nx, 1] = error estimate along each dimension
%
% NOTES:
% algorithm from:
% http://www.math.usm.edu/lambers/mat460/fall09/lecture29.pdf
%
a = tSpan(1);
b = tSpan(2);
h = b-a;
f0 = fun(tSpan);
nx = size(f0,1);
if isscalar(tol)
tol = tol*ones(nx,1);
end
nMin = 4; % Complete at least this many iterations
nMax = 12; % Maximum iteration count
nSubSegment = 4; % Sub-divide segment if max iteration is reached
T = zeros(nMax,nMax,nx); % (iteration, extrapolation, dimension)
Err = zeros(nMax,nx); %(extrapolation, dimension)
T(1,1,:) = 0.5*h*sum(f0,2);
h = h/2;
converged = false;
for j=2:nMax
% Trapazoid method
i = 1:2^(j-2);
t = a+h*(2*i-1);
f = fun(t);
T(j,1,:) = 0.5*T(j-1,1,:) + reshape(h*sum(f,2),1,1,nx);
% Richardson extrapolation
for k=2:j
T(j,k,:) = T(j,k-1,:) + ...
( 1/(4^(k-1)-1) )*( T(j,k-1,:) - T(j-1,k-1,:) );
end
h = h/2;
% Check the error estimate for convergence
Err(j,:) = T(j,k,:) - T(j-1,k-1,:);
err = abs(Err(j,:))';
if all( err < tol ) && j > nMin
converged = true;
break;
end
end
x = reshape(T(j,j,:),nx,1);
if ~converged %Then non-smooth problem. Recursively sub-divide interval.
time = linspace(tSpan(1), tSpan(2), nSubSegment+1);
x = zeros(nx,1);
err = zeros(nx,1);
for i=1:nSubSegment
[xTmp, errTmp] = rombergQuadrature(fun,time([i, i+1]),tol);
x = x + xTmp;
err = max(err,errTmp);
end
end
end
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。