主题:帮忙看看这个程序(在线等)
function [xc,yc,r]=tlscirc(xd,yd);
% Total least squares (TLS) curve fitting minimizes the sum of squared
% orthogonal distances from the data to the curve.
warning off;
if nargin==0;
xd=rand(1,8); % x-axis data of the centre of a circle
yd=rand(1,8); % y-axis data of the centre of a circle
end
xk=1:length(xd); % the number of order
% fitting function: F(x,y)=(x-xc)^2+(y-yc)^2-r^2
fdata=zeros(1,length(xd)); % value of F(x,y)
x0=rand(1,3);
for k=1:10; % many times fit
x0= lsqcurvefit(@myfun, x0, xk, fdata)
end
x=x0;
t=linspace(0,pi*2,100);
z=x(1)+x(2)*i+x(3)*exp(i*t);
plot(xd,yd,'r*');hold on;
plot(z);
function F = myfun(x,xk);
global xd;
global yd;
F=(x(1)-xd(xk)).^2+(x(2)-yd(xk)).^2-x(3)^2;
请问哪里需要改动?谢谢达人
% Total least squares (TLS) curve fitting minimizes the sum of squared
% orthogonal distances from the data to the curve.
warning off;
if nargin==0;
xd=rand(1,8); % x-axis data of the centre of a circle
yd=rand(1,8); % y-axis data of the centre of a circle
end
xk=1:length(xd); % the number of order
% fitting function: F(x,y)=(x-xc)^2+(y-yc)^2-r^2
fdata=zeros(1,length(xd)); % value of F(x,y)
x0=rand(1,3);
for k=1:10; % many times fit
x0= lsqcurvefit(@myfun, x0, xk, fdata)
end
x=x0;
t=linspace(0,pi*2,100);
z=x(1)+x(2)*i+x(3)*exp(i*t);
plot(xd,yd,'r*');hold on;
plot(z);
function F = myfun(x,xk);
global xd;
global yd;
F=(x(1)-xd(xk)).^2+(x(2)-yd(xk)).^2-x(3)^2;
请问哪里需要改动?谢谢达人