% FILE d021hlp.m begins.
% A'(k) = 2 \sum_{j=1}^m {- (x_j-s)(y_j-t -k(x_j -s))}			
% The requirement A'(k) =0 yields
% k= numer/denom; 
% denom= sum((x(j)-s)*(x(j)-s))
% numer= sum((x(j)-s)*(y(j)-t))
% The LSQ-line is y= t+ k*(x-s) = k*x + (t-k*s) 
clear
close all
%path(path,'../../util')
%startup
x=zeros(20);
y=zeros(20);
s=5; t=1.2;
%s=0.0; t=0.0;
for j=1:20
  x(j)=0.5*j;   
%  y(j)= 0.3*x(j)*log(x(j)) + 0.1*sin(30*x(j));
  y(j)= 0.3*x(j) + 0.1*sin(30*x(j));
end 
denom= sum((x(j)-s).*(x(j)-s));
numer= sum((x(j)-s).*(y(j)-t));
k= numer/denom; 
% Write the solution here:....
plot(s,t,'k.',x,y,'k+','MarkerSize',20)
% FILE d021hlp.m ends.
