我期待這個表達式整合:如何在MATLAB中正確設置數值積分?
不過,我似乎有問題,建立功能。作爲this MATLAB的解釋概括,我已經定義了一個名爲「NDfx.m」它看起來像這樣一個單獨的函數:
function [ y ] = NDfx(x)
y = (1/sqrt(2*pi))*exp(-.5*x^2); % Error occurs here
end
然而,當我把它稱爲我的主函數中我在註釋行得到一個錯誤之上。我的主要功能如下:
function[P] = NormalDistro(u,o2,x)
delta = x-u;
dev = abs((delta)/o2); % Normalizes the parameters entered into function
P_inner = quad(@NDfx,-dev,dev); % Integrates function NDfx from -dev to dev (error here)
P_outer = 1 - P_inner; % Calculation of outer bounds of the integral
if delta > 0
P = P_inner + (P_outer/2);
elseif delta < 0
P = P_outer/2;
elseif dev == 0
P = .5;
end
end
,我得到特定的錯誤是:在==
錯誤> MPOWER
輸入必須是標量和方陣
或者您可以切換到Mathematica,例如您的答案 - www.wolframalpha.com/input/?i=Integrate[e^(-x^2/2)/Sqrt[2Pi],x] – Margus 2011-02-24 04:38:15
儘管這很棒我正在爲其他人編寫一個函數,以便在MATLAB中使用這個函數... – KronoS 2011-02-24 04:40:49