⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 custom_finv.m

📁 toolbox of BVQX, This is the access between BV and matlab. It will help you to analysis data from BV
💻 M
字号:
function x = custom_finv(p, v1, v2)
% custom_finv  - returns inverse of the F-distribution
%
% FORMAT:       x = custom_finv(p, v1, v2);
%
% Input fields:
%
%       p           CDF of F distribution with v1, v2 d.f. at points x
%       v1, v2      d.f. of distribution function
%
% Output fields:
%
%       x           F-variate

% Version:  v0.6f
% Build:    7070510
% Date:     Jul-05 2007, 10:38 AM CEST
% Author:   KH <Kurt.Hornik@wu-wien.ac.at>

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

% create output
x = zeros(osize);
x(p < 0 | p > 1 | isnan(p) | ~(v1 > 0) | ~(v2 > 0)) = NaN;
x(p == 1 & v1 > 0 & v2 > 0) = Inf;

% regular cases
k = find(p > 0 & p < 1 & v1 > 0 & v1 > 0);
if ~isempty(k)
    if numel(v1) == 1 && ...
        numel(v2) == 1
        x(k) = ((1 ./ custom_betainv(1 - p(k), v2 / 2, v1 / 2) - 1) * v2 ./ v1);
    elseif numel(v1) == 1
        x(k) = ((1 ./ custom_betainv(1 - p(k), v2(k) ./ 2, v1 / 2) - 1) .* ...
            v2(k) ./ v1);
    elseif numel(v2) == 1
        x(k) = ((1 ./ custom_betainv(1 - p(k), v2 / 2, v1(k) ./ 2) - 1) .* ...
            v2 ./ v1(k));
    else
        x(k) = ((1 ./ custom_betainv(1 - p(k), v2(k) ./ 2, v1(k) ./ 2) - 1) .* ...
            v2(k) ./ v1(k));
    end
end

% reshape
x = reshape(x, osize);

⌨️ 快捷键说明

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