MATLAB newbie here。我試圖順利近似Heaviside函數heaviside(x)
。爲此,我正在做一個具有凹凸功能的標準乳化過程。這是嵌套功能smooth
,我認爲應該執行該過程(如果這是一個不合適的解決方案,我很抱歉)。MATLAB-嘗試繪製嵌套函數時出現錯誤
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);
我可能是錯的,但我不認爲,你認爲這是組合爲強大。當您將撰寫分號的分號取消時會發生什麼? d = compose(nbump,quot,x,q) – dmm
對於數值積分,請使用['integral()'](http://www.mathworks.co.uk/help/matlab/ref/integral.html)或相關(在另見部分) – Oleg