最小二乘法圆拟合求半径 matlab编程实现
数据有八个点,用最小二乘法圆拟合,并求出半径?x=[565.454562.058561.39563.782567.941571.255571.938569.5]y=[52...
数据有八个点,用最小二乘法圆拟合,并求出半径? x=[ 565.454
562.058
561.39
563.782
567.941
571.255
571.938
569.5 ]
y=[528.012
525.544
521.447
518.108
517.407
519.857
523.953
527.356 ]怎么编写matlab程序进行计算?可以发到我邮箱1114672089@qq.com 展开
562.058
561.39
563.782
567.941
571.255
571.938
569.5 ]
y=[528.012
525.544
521.447
518.108
517.407
519.857
523.953
527.356 ]怎么编写matlab程序进行计算?可以发到我邮箱1114672089@qq.com 展开
2个回答
展开全部
function [R,A,B]=circ(x,y,N)%定义函数circ
%最小二乘法拟合圆曲线
x1 = 0;
x2 = 0;
x3 = 0;
y1 = 0;
y2 = 0;
y3 = 0;
x1y1 = 0;
x1y2 = 0;
x2y1 = 0;
for i = 1 : N
x1 = x1 + x(i);
x2 = x2 + x(i)*x(i);
x3 = x3 + x(i)*x(i)*x(i);
y1 = y1 + y(i);
y2 = y2 + y(i)*y(i);
y3 = y3 + y(i)*y(i)*y(i);
x1y1 = x1y1 + x(i)*y(i);
x1y2 = x1y2 + x(i)*y(i)*y(i);
x2y1 = x2y1 + x(i)*x(i)*y(i);
end
%可解得:
C = N * x2 - x1 * x1;
D = N * x1y1 - x1 * y1;
E = N * x3 + N * x1y2 - (x2 + y2) * x1;
G = N * y2 - y1 * y1;
H = N * x2y1 + N * y3 - (x2 + y2) * y1;
a = (H * D - E * G)/(C * G - D * D);
b = (H * C - E * D)/(D * D - G * C);
c = -(a * x1 + b * y1 + x2 + y2)/N;
%得出A,B,R的估计拟合值
A = a/(-2);
%x 坐标
B = b/(-2);
%y 坐标
R = sqrt(a * a + b * b - 4 * c)/2;
%半径
%最小二乘法拟合圆曲线
x1 = 0;
x2 = 0;
x3 = 0;
y1 = 0;
y2 = 0;
y3 = 0;
x1y1 = 0;
x1y2 = 0;
x2y1 = 0;
for i = 1 : N
x1 = x1 + x(i);
x2 = x2 + x(i)*x(i);
x3 = x3 + x(i)*x(i)*x(i);
y1 = y1 + y(i);
y2 = y2 + y(i)*y(i);
y3 = y3 + y(i)*y(i)*y(i);
x1y1 = x1y1 + x(i)*y(i);
x1y2 = x1y2 + x(i)*y(i)*y(i);
x2y1 = x2y1 + x(i)*x(i)*y(i);
end
%可解得:
C = N * x2 - x1 * x1;
D = N * x1y1 - x1 * y1;
E = N * x3 + N * x1y2 - (x2 + y2) * x1;
G = N * y2 - y1 * y1;
H = N * x2y1 + N * y3 - (x2 + y2) * y1;
a = (H * D - E * G)/(C * G - D * D);
b = (H * C - E * D)/(D * D - G * C);
c = -(a * x1 + b * y1 + x2 + y2)/N;
%得出A,B,R的估计拟合值
A = a/(-2);
%x 坐标
B = b/(-2);
%y 坐标
R = sqrt(a * a + b * b - 4 * c)/2;
%半径
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询