【问题标题】:Matlab numerical integral avoid pointMatlab数值积分避让点
【发布时间】:2015-09-11 08:07:46
【问题描述】:

我正在使用integralN 函数对复杂函数进行 4 维积分(如果您有兴趣,我将其放在文章末尾)。

我正在从(r1, r2) = (1.8, 1.8) 开始进行集成。从分析上讲,这个函数是在r1 = r2 定义的,然而,在数值上,Matlab 将所有具有匹配坐标的东西视为NaN

有什么办法可以避免这种行为吗?作为一个仅供参考,将eps 加到一个到下限是行不通的。

f1 =@(r) 5*r.^2 + 2;
f2 =@(r) 2*r.^2 + 12;

f1p = der(f1);
f2p = der(f2);

dF = @(r1,t1,r2,t2)((r1.*r2.*(f1(r1)-f2(r2)+(-r1+r2.*cos(t1-t2)).*f1p(r1)).*(f1(r1)-f2(r2)+(r2-r1.*cos(t1-t2)).*f2p(r2)))./(pi.*(r1.^2+r2.^2-2.*r1.*r2.*cos(t1-t2)+(f1(r1)-f2(r2)).^2).^2))

function df = der(f)
    syms x
    df = matlabFunction(diff(f(x)));
end

【问题讨论】:

  • 请添加您用于integralN的调用命令。

标签: matlab numerical-integration


【解决方案1】:

我想出了一个强制正确输出的环绕函数,其中funMatchfunNoMatch 是4d 函数,我的限制存储在Limit 中。

f = @(r1, t1, r2, t2) selective(funMatch, funNoMatch, r1 == r2, r1, t1, r2, t2);
res = integralN(f, Limit(1,1), Limit(1,2), Limit(2,1), Limit(2,2), Limit(3,1), Limit(3,2), Limit(4,1), Limit(4,2), 'RelTol',1e-1, 'AbsTol',1e-3);

function res = selective(funMatch, funNoMatch, cond, varargin)
    res = zeros(size(cond));

    Match = cellfun(@(x) x(cond), varargin, 'uni', 0);
    NoMatch = cellfun(@(x) x(~cond), varargin, 'uni', 0);

    res(cond) = funMatch(Match{:});
    res(~cond) = funNoMatch(NoMatch{:});
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-08
    • 2021-07-20
    • 2013-05-14
    • 2019-07-19
    • 1970-01-01
    • 1970-01-01
    • 2015-02-13
    • 2018-08-16
    相关资源
    最近更新 更多