function [a,err] = malbffit(t,y,tmin,tmax)
%Take data and find best quadratic and Malthusian models
q = polyfit(t,y,2);
err(1) = (sum(((q(1)*t.^2 + q(2)*t + q(3)) - y).^2)).^0.5;
a(1) = q(1); a(2) = q(2); a(3) = q(3);
lnp = log(y);
w = polyfit(t,lnp,1);
p0 = exp(w(2));
err(2) = (sum(((p0*exp(w(1)*t)) - y).^2)).^0.5;
a(4) = w(1); a(5) = w(2); a(6) = p0;

%Plot Data and Models
xx = linspace(tmin,tmax,250);
r = fminsearch(@mallstsq,[a(6),a(4)],[],t,y);
err(3) = (sum(((r(1)*exp(r(2)*t)) - y).^2)).^0.5;
bf = r(1)*exp(r(2)*xx);
plot(t,y,'bo');
hold on
plot(xx,a(1)*xx.^2+a(2)*xx+a(3),'b-','LineWidth',1.5);
plot(xx,a(6)*exp(w(1)*xx),'m-','LineWidth',1.5);
plot(xx,bf,'r-','LineWidth',1.5);
grid
ylim([0,450]);
legend('Data','Quadratic','Malthusian','Best Fit','Location','northwest');

% Set up fonts and labels for the Graph
fontlabs = 'Times New Roman';  
xlabel('$t$, years after 1790','FontSize',16,'FontName',fontlabs, ...
    'interpreter','latex');  
ylabel('Population (in Millions)','FontSize',16,'FontName',fontlabs, ...
    'interpreter','latex'); 
mytitle = 'U. S. Population';
title(mytitle,'FontSize',16,'FontName', ...
    'Times New Roman','interpreter','latex'); 
set(gca,'FontSize',16);

print -depsc us_malbf.eps
end

