且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

椭圆的协方差矩阵

更新时间:2021-08-19 03:33:54

仅通过纯逆向工程(我对这种材料已经不熟悉了),我可以做到:

Just by pure reverse engineering (I'm not familiar anymore with this material), I can do this:

%// Generate circle
R = 189;
t = linspace(0, 2*pi, 1000).';
x = R*cos(t);
y = R*sin(t);

%// Find the radius?
[~,L] = eig( cov([x,y]) );

%// ...hmm, seems off by a factor of sqrt(2)
2*sqrt( diag(L) )        

%// so it would come out right when I'd include a factor of 1/2 in the sqrt():
2*sqrt( diag(L)/2 )        

因此,让我们测试一下有关一般椭圆的理论:

So, let's test that theory for general ellipses:

%// Random radii
a1 = 1000*rand;
a2 = 1000*rand;

%// Random rotation matrix
R = @(a)[
    +cos(a) +sin(a); 
    -sin(a) +cos(a)];

%// Generate pionts on the ellipse 
t = linspace(0, 2*pi, 1000).';
xy = [a1*cos(t)  a2*sin(t);] * R(rand);

%// Find the deviation from the known radii
%// (taking care of that the ordering may be different)
[~,L] = eig(cov(xy));
min(abs(1-bsxfun(@rdivide, 2*sqrt( diag(L)/2 ), [a1 a2; a2 a1])),[],2)

总是返回可接受的较小值.

which always returns something acceptably small.

因此,似乎可行:)任何人都可以验证这确实正确吗?

So, seems to work :) Can anyone verify that this is indeed correct?