custom_tinv.m

来自「toolbox of BVQX, This is the access betw」· M 代码 · 共 48 行

M
48
字号
function x = custom_tinv(p, v)
% custom_tinv  - returns inverse CDF of the Student's t-distribution
%
% FORMAT:       x = custom_tinv(p, v);
%
% Input fields:
%
%       p           CDF of t distribution with v d.f. at points x
%       v           d.f. of distribution function
%
% Output fields:
%
%       x           t-variate (Student's t has range (-Inf,Inf))

% Version:  v0.6f
% Build:    7070509
% Date:     Jul-05 2007, 9:51 AM CEST
% Author:   Alois Schloegl <a.schloegl@ieee.org>

% argument check
if nargin < 2 || ...
   ~isa(p, 'double') || ...
   ~isa(v, 'double') || ...
    isempty(v) || ...
    any(isnan(p(:))) || ...
    any(isinf(v(:)) | isnan(v(:)) | v(:) < 0)
    error( ...
        'BVQXtools:BadArgument', ...
        'Missing or invalid argument given.' ...
    );
end
if isempty(p)
    x = [];
    return;
end
osize = size(p);
if numel(p) == 1 && ...
    numel(v) > 1
    osize = size(v);
end
p = p(:);
v = v(:);

% calculus
x = reshape(...
    (sign(p - 1/2) .* sqrt(v ./ custom_betainv(2 * min(p, 1-p), v ./ 2, 1/2) - v)), ...
    osize);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?