iscor.m

来自「copua是金融数学计算中的一类新模型。本代码提供了最常用的copula模型」· M 代码 · 共 25 行

M
25
字号
function t = iscor(R)
%ISCOV Is a matrix a correlation matrix?
%   T = ISCOV(R) returns a logical value indicating whether or not the
%   matrix R is a valid correlation matrix, i.e., whether it is symmetric,
%   positive semidefinite, with ones on the diagonal.

%   Written by Peter Perkins, The MathWorks, Inc.
%   Revision: 1.0  Date: 2003/09/05
%   This function is not supported by The MathWorks, Inc.
%
%   Requires MATLAB R13.

[n,m] = size(R);
% test square, unit diagonal, symmetric
if (n == m) && all(diag(R) == 1) && all(all(abs(R - R') < 10*eps))
    e = eig(.5*(R + R'));
    % test positive semidefinite
    if all(e > -abs(max(e))*n*eps)
        t = true;
    else
        t = false;
    end
else
    t = false;
end

⌨️ 快捷键说明

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