首页 文章

拟合椭圆而不倾斜数据

提问于
浏览
-2

我想在我的数据上安装一个没有倾斜的椭圆 . 这是一个没有倾斜的椭圆方程:

a*x^2 + b*y^2 + c*x + d*y = e

我发现这个解决方案(https://stackoverflow.com/a/12717181/3179989)很有趣,但不知道如何更改参数以获得解决我的问题的方法 .

任何帮助表示赞赏 .

编辑:这是我正在使用的代码:

[y.^2,x,y,ones(numel(x),1)]\x.^2

ans =
1.0e+04 *
-0.0000
 0.0168
-0.0014
 3.6390

1 回答

  • 1

    这确实有效:

    %// Creating some test data
    x=sin(pi*(2*rand(50,1)-1))+(2*rand(size(x))-1)*.5;x=x./max(abs(x));
    y=(sqrt(1-x.^2)+(2*rand(size(x))-1)*.5).*sign(rand(size(x))-0.5)+.5*x;
    
    %// Setup Van der Monde matrices and solve equations
    A=[y.^2,x.*y,x,y,ones(numel(x),1)]\x.^2
    B=[y.^2,x,y,ones(numel(x),1)]\x.^2
    
    plot(x,y,'o') %// Plot initial data
    hold on
    %// Plotting results the lazy way!
    [X,Y]=meshgrid(1.5*(min([x;y]):.001:max([x;y])));
    contour(X,Y,-X.^2+A(1)*Y.^2+A(2)*X.*Y+A(3)*X+A(4)*Y+A(5),[0 0],'b')
    contour(X,Y,-X.^2+B(1)*Y.^2+B(2)*X+B(3)*Y+B(4),[0 0],'k')
    hold off
    

    蓝色是原始椭圆,黑色是非旋转椭圆

    Ellipses!

相关问题