0

MATLAB新手在这里。我正在尝试对 Heaviside 函数进行平滑近似heaviside(x)。为此,我正在做一个带有凹凸功能的标准缓和程序。smooth这是我认为应该执行该过程的嵌套函数(如果它是一个不雅的解决方案,我很抱歉)。

function c = smooth(q,y,e)
c = e.^-1*int(igrand(q,y),y,-2,2);
igrand(q,y)

function i = igrand(q,y)
i = dbump(q)*heaviside(y);
dbump(q)

    function d = dbump(q)
    d = compose(nbump,quot,x,q);
    nbump(x);
    quot(x,y,e);


        function n = nbump(x)
        n = bump(x)*(ibump(x)).^-1;
        ibump(x)

            function i = ibump(x)
            i = integral(@bump, -2, 2);
            bump(x)

                function b = bump(x)
                region1 = abs(x) < 1;
                b(region1) = (exp(-1./(1 - x(region1).^2)));

                region2 = abs(x) >= 1;
                b(region2) = 0;

        function q = quot(x,y,e)
        q = (x-y)./e;
        end
                end
            end
        end
    end
end

end

另外,请原谅我的格式。最后一个end应该在前一个的左侧。此外,定义smooth应该在身体其余部分的左侧。

我选择x = -2:.01:2e = .1syms y real但是,当我运行时plot(x, smooth(q,y,e)),我收到以下错误。

Error using smooth/igrand/dbump/nbump (line 16)
Not enough input arguments.

Error in smooth/igrand/dbump (line 10)
d = compose(nbump,quot,x,q);

Error in smooth/igrand (line 6)
i = dbump(q)*heaviside(y);

Error in smooth (line 2)
c = e.^-1*int(igrand(q,y),y,-2,2);

当我实际编写函数时出现的唯一错误是quot底部附近的下划线,表示该函数可能未使用。但是,我不是用 来作曲nbump吗?

编辑:我已经更改compose(nbump,quot,x,q);为 justnbump(quot(x,y,e));并且更改了所有变量,以便它们对齐(不再有 q)。现在,当我运行时plot(x,smooth(x,y,e)),它会运行一段时间,然后停止并给我以下错误消息。

Error using symengine (line 58)
Unable to prove 'abs(10*y + 20) < 1' literally. To test the statement mathematically, use isAlways.

Error in sym/subsindex (line 1554)
X = find(mupadmex('symobj::logical',A.s,9)) - 1;

Error in sym>privformat (line 2357)
x = subsindex(x)+1;

Error in sym/subsref (line 1578)
[inds{k},refs{k}] = privformat(inds{k});

Error in bump (line 3)
b(region1) = (exp(-1./(1 - x(region1).^2)))

Error in smooth/igrand/dbump/nbump (line 16)
n = bump(x)*(ibump(x)).^-1;

Error in smooth/igrand/dbump (line 10)
d = nbump(quot(x,y,e));

Error in smooth/igrand (line 6)
i = dbump(x,y,e)*heaviside(y);

Error in smooth (line 2)
s = e.^-1*int(igrand(x,y,e),y,-2,2);

4

1 回答 1

0

正如错误所说,您在nbump没有输入的情况下调用:

Error in smooth/igrand/dbump (line 10)
d = compose(nbump,quot,x,q); 
于 2013-09-25T17:27:48.353 回答