% or change to what you have the files saved as 
load xdata
load ydata

numdatapts = length(xdata);
x=xdata;
y=ydata;
clf
plot(x,y,'*')
hold on
totsqerr=0
totsqerr2=0
for i=1:numdatapts  % leave out each datapoint in turn
  if i==1
    xuse=x(2:numdatapts)
    yuse=y(2:numdatapts)
  elseif i==numdatapts
    xuse=x(1:numdatapts-1)
    yuse=y(1:numdatapts-1)
  else
    xuse=x([1:i-1, i+1:numdatapts])
    yuse=y([1:i-1, i+1:numdatapts])
  end
  xleftout=x(i);
  A = [ xuse' xuse.^2' xuse.^3' xuse.^4' xuse.^5' ones(length(xuse),1)];
  mnpqrb=A\yuse';
  mnb=A(:,[1:2 6])\yuse';

  xp=0:.1:6;
  yp=mnpqrb(1)*xp +mnpqrb(2)*xp.^2+ mnpqrb(3)*xp.^3 + mnpqrb(4)*xp.^4 + mnpqrb(5)*xp.^5 + mnpqrb(6);
  plot(xp,yp,'k')
  yp2=mnb(1)*xp + mnb(2)*xp.^2 +mnb(3);
  plot(xp,yp2,'r')
  %%compute yleftout
  yleftout= predictyval(xleftout,mnpqrb);
  yleftout2= predictyval(xleftout,mnb);
  %%% compute squared error for left out point
  sqerr=(yleftout-y(i))^2
  sqerr2=(yleftout2-y(i))^2
  totsqerr=sqerr+totsqerr;
  totsqerr2=sqerr2+totsqerr2;
end
rootmeansqerr=sqrt(totsqerr/numdatapts)
rootmeansqerr2=sqrt(totsqerr2/numdatapts)
