function no_result=least_squares()
% least_squares.m
% Least Squares Curve Fitting Demonstration
hold off

slope=4*(rand(1)-0.5)
yintercept=2*(rand(1)-0.5)

%Make some data, complete with 'noise'
global datax datay %share these with the badness function (below)
datax = 0:0.05:1.0;
datay = (slope*datax)+yintercept;
plot(datax,datay,'r--'); %Plot the theory used to generate the data
hold; %save current display for overplotting
[M,N] = size(datax);
error = 0.5*(rand(M,N)-0.5).*(max(datay)-min(datay)); %create noise
datay = datay + error; %add noise to data
plot(datax,datay,'ro'); %Overlay more realistic noised data

%Find best fit slope and yintercept from noised data
result = amoeba('badness',[0,0],20);
slope=result(1)
yintercept=result(2)
result = amoeba('badness',result,20);
slope=result(1)
yintercept=result(2)

%Generate best fit curve, plot for comparison
fit_y = (slope*datax)+yintercept;
plot(datax,fit_y,'b-'); %Plot the theory
hold off
%end of main program




