[英]Octave: “'ncx2cdf' undefined” error
我正在尝试从八度运行M文件,但出现此错误:
Octave evaluation error: 'ncx2cdf' undefined
Apparently the non-central chi-square distribution is simply defined as 1 minus the Marcum Q function . 显然,非中心卡方分布简单定义为1减去Marcum Q函数 。 The signal package at octave-forge provides an implementation for this function (seemingly compatible with matlab).
八度伪造的信号包提供了此功能的实现 (似乎与matlab兼容)。
Therefore you could presumably write your own ncx2cdf
function simply as follows: 因此,您大概可以简单地编写自己的
ncx2cdf
函数,如下所示:
function Out = myncx2cdf (X, V, Delta)
Out = 1 - marcumq (sqrt (Delta), sqrt (X), V/2);
end
Confirmed in matlab: 在matlab中确认:
>> X = randi(100, [1,20]); V = 4; Delta = 10;
>> ncx2cdf(X, V, Delta)
ans =
1.0000 0.9410 0.9999 1.0000 1.0000 1.0000 1.0000 0.5549 0.6093 0.9410 1.0000 0.9410 1.0000 0.9279 1.0000 0.9920 0.8183 0.9410 1.0000 0.9997
>> 1 - marcumq(sqrt(Delta), sqrt(X), V/2)
ans =
1.0000 0.9410 0.9999 1.0000 1.0000 1.0000 1.0000 0.5549 0.6093 0.9410 1.0000 0.9410 1.0000 0.9279 1.0000 0.9920 0.8183 0.9410 1.0000 0.9997
Octave session for the same X, V, and Delta: 相同的X,V和Delta的八度会话:
octave:34> pkg load signal
octave:35> 1 - marcumq(sqrt(Delta), sqrt(X), V/2)
ans =
1.00000 0.94105 0.99988 1.00000 1.00000 1.00000 0.99996 0.55492 0.60929 0.94105 1.00000 0.94105 1.00000 0.92793 1.00000 0.99203 0.81831 0.94105 1.00000 0.99972
Note that the degrees of freedom parameter V is restricted to even values with this implementation; 注意,在该实施方式中,自由度参数V限制为偶数; if you'd like to use odd degrees of freedom too, eg 5, this could be interpolated from the result for V=4 and V=6 (this seems to work well in practice).
如果您也想使用奇数自由度,例如5,则可以从V = 4和V = 6的结果中进行插值(这在实践中似乎效果很好)。
here is a easy implementation of non-central chi square distribution: 这是非中心卡方分布的简单实现:
function f = ncx2pdf(x, n, lambda, term = 32)
f = exp(-lambda/2) * arrayfun(@(x) sum_expression([0:term],x,n,lambda), x);
function t = sum_expression(j,v,n,l)
# j is vector, v is scalar.
numerator = (l/2).^j .* v.^(n/2+j-1) * exp(-v/2);
denominator = factorial(j) .* 2.^(n/2+j) .* gamma(n/2+j);
t = sum(numerator ./ denominator);
end
end
here is the function file , put it in your octave path. 这是函数文件 ,放在您的八度音程中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.