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:2
,e = .1
和syms 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);
更改为nbump(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);
答案 0 :(得分:0)
如错误所示,您在没有输入的情况下调用nbump
:
Error in smooth/igrand/dbump (line 10)
d = compose(nbump,quot,x,q);