least square circle, why doesn't it work?

1 回表示 (過去 30 日間)
Jenny Andersen
Jenny Andersen 2019 年 12 月 10 日
編集済み: Matt J 2019 年 12 月 10 日
Hi, so I have four data points (x and y) and I want to find A and B from least square equation Ax=B (to fit the circle's equation). I also want to solve x. I have tried the following but x the circle is not visiable. What am I doing wrong?
x = [6; 5; -1; 1];
y = [4; 6; 5; -1];
plot(x,y,'*')
% circle's equation x^2+y^2 = 2xc1+2yc2+c3
A = [2.*x,2.*y,ones(n,3)]
B = [x^2 + y^2];
c = A\B;
plot(A,B)
  3 件のコメント
Ridwan Alam
Ridwan Alam 2019 年 12 月 10 日
what is 'a' and 'b'?
Jenny Andersen
Jenny Andersen 2019 年 12 月 10 日
I meant to write A and B. It's been changed in the script above now.

サインインしてコメントする。

採用された回答

Matt J
Matt J 2019 年 12 月 10 日
編集済み: Matt J 2019 年 12 月 10 日
As I mentioned in your other post, your approach is not a good way to fit a circle. However, assuming you must do it this way, your main mistake was in the plotting, not in the fitting.
x = [6; 5; -1; 1];
y = [4; 6; 5; -1];
n=numel(x);
% circle's equation x^2+y^2 = 2xc1+2yc2+c3
A = [2.*x,2.*y,ones(n,1)];
B = [x.^2 + y.^2];
c = A\B;
fun=@(x,y) x.^2 + y.^2-c(1)*2*x-c(2)*2*y-c(3);
plot(x,y,'*')
hold on
fimplicit(fun,[-3,8])
hold off
axis equal
  1 件のコメント
Jenny Andersen
Jenny Andersen 2019 年 12 月 10 日
Thanks alot!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by