% function to compute square error in model of world
% population
function sqerr=wp_fun(xx);

% xx - is the input vector of parameters

a=xx(1);
b=xx(2);
popdt=[-10000     1;  
 -8000     5;  
 -6500     5;  
 -5000     5;  
 -4000     7;  
 -3000    14;  
 -2000    27;  
 -1000    50;  
  -500   100;  
  -400   162; 
  -200   150;  
     1   170;  
   200   190;  
   400   190;  
   500   190;  
   600   200;  
   700   207;  
   800   220;  
   900   226;  
  1000   254;  
  1100   301;  
  1200   360;  
  1250   400;  
  1300   360;  
  1340   443;  
  1400   350;  
  1500   425;  
  1600   545;  
  1650   470;  
  1700   600;  
  1750   629;  
  1800   813; 
  1850 1128; 
  1900 1550; 
  1910 1750; 
  1920 1860; 
  1930 2070; 
  1940 2300; 
  1950 2400];

tim=popdt(:,1);
popul=popdt(:,2);


for kk=1:length(tim)
   err(kk)=exp(a*tim(kk)+b)-popul(kk);
end

sqerr=err*err';