Hi everyone,
Forgive me, I am no expert at MATLAB. I would appreciate it greatly if someone could explain to me the method of nonlinear least squares and how to fit it with a circle of random points. Here's what I have so far:
% radius information-------------------------------------------------------
r = 10; % constant radius
Rc = @(x,y,z) (x.^2 + y.^2 + z.^2).^(1/2); % radius as a function
n = rand(1000,3); % generate random points on nominal circle
xc = n(:,1);yc = n(:,2); % separate into coordinates
zc = n(:,3);%--------------------------------------------------------------------------
% angular information------------------------------------------------------
theta = linspace(0,2*pi,1000); % plot bounds
theta = theta';%--------------------------------------------------------------------------% generate random radii----------------------------------------------------
R = Rc(xc,yc,zc);R(:,2) = R(:,1); % same radii in all directions
R(:,3) = R(:,1);p = n + (r/100)*R; % generate plot points around the circle
figure(1)polar(theta,Rc(xc,yc,zc))%--------------------------------------------------------------------------% Least Squares fitting----------------------------------------------------
e = dist(p,R');perf = sse(e);lsqrfit = lsqr(e,Rc(xc,yc,zc),[],1000);%--------------------------------------------------------------------------
So from what I understand, the residuals (errors) need to be found and then the sum of squares of the residuals need to be found. After that I am not sure where to go. Thanks for all the help.
Ian
Best Answer