2014-10-01|最小二乘法拟合圆公式推导及matlab实现最小二乘法(leastsquaresanalysis)是一种数学优化技术,它通过最小化误差的平方和找到一组数据的最佳函数匹配。最小二乘法是用最简的方法求得一些绝对不可知的真值,而令误差平方之和为最小。最小二乘法通常用于曲线拟合(leastsquaresfitting)。这里有拟合圆曲线的公式推导过程和vc实现。matlab实现:function[xc,yc,R,f]=circfit(x,y)%CIRCFITFitsacircleinx,yplane%[XC,YC,R,A]=CIRCFIT(X,Y)%Resultiscenterpoint(yc,xc)andradiusR.Aisan%optionaloutputdescribingthecircle'sequation:%x^2+y^2+a(1)*x+a(2)*y+a(3)=0closeall;clearall;clc;n=length(x);xx=x.*x;yy=y.*y;xy=x.*y;A=[sum(x)sum(y)n;sum(xy)sum(yy)...sum(y);sum(xx)sum(xy)sum(x)];B=[-sum(xx+yy);-sum(xx.*y+yy.*y);-sum(xx.*x+xy.*y)];f=A\B;xc=-.5*f(1);yc=-.5*f(2);R=sqrt((f(1)^2+f(2)^2)/4-f(3));end