我遇到一個奇怪的問題quad
函數。 我用quad
計算簡單的整體,它工作了10至20次,然後Matlab的發出以下錯誤:關於在MATLAB中使用quad
Error using quad (line 75)
The integrand function must return an output vector of the same length as the input vector.
yteor(k) = quad(@(q)(exp(-(q).^2).*q.^2/(k.^2+1)), 0, 1);
這裏q和k爲標量。 我無法弄清楚什麼是錯的,爲什麼它幾個小時前工作。
編輯
這裏是我的代碼
for k=1:100,
xteor(k)=step*k;
yteor(k)=quad(@(q)(exp(-(q).^2).*q.^2/((step.*k+1).^2)),0,1);
end plot(xteor,yteor,'r');
錯誤消息似乎很自我解釋。你能顯示你的代碼嗎? (理想情況下,工作,不工作) – FabienAndre
整個代碼太大,所以我會發送整合和繪製圖形的部分: –
對於k = 1:100 xteor(k)= step * k; (q)= exp( - (q)。^ 2)。* q。^ 2 /((step。* k + 1)。^ 2)),0,1); end plot(xteor,yteor,'r'); –