%% Example US Census clear all, close all %load adis data x=1981:2004; y=[260 992 2717 5341 8224 13195 21355 32196 35230 43352 45524 47572 ... 106618 77474 71073 68808 60270 47915 46143 41795 43158 43578 44963 42514]; figure(1), plot(x,y,'o') axis([1981,2004,0,max(y)]) xlabel('Years') ylabel('aids cases') x = x(1:12); y = y(1:12); figure(2) plot(x,y,'o') axis([1981,1992,0,max(y)]) xlabel('year') ylabel('aids cases') %% Compute k and y(0) in exponential model using least squares. t = 0:1:length(x)-1; p0 = [y(1),1]; p=nlinfit(t,y,@(p,x) p(1)*exp(p(2)*x),p0); exp_fit = p(1)*exp(p(2)*t); figure(2) plot(x,y,'o',x,exp_fit) axis([1981,1992,0,max(y)]) xlabel('Years') ylabel('aids cases') legend(['Data','Exponential Fit']) %% Compute k, M, and y(0) in logisitic model using least squares. t = 0:1:length(x)-1; p0 = [y(1),1,max(y)]; p=nlinfit(t,y,@(p,x) p(1)*p(3) ./ (p(1) + (p(3)-p(1))*exp(-p(2)*x)),p0); logistic_fit = p(1)*p(3) ./ (p(1) + (p(3)-p(1))*exp(-p(2)*t)); figure(3) plot(x,y,'o',x,logistic_fit) axis([1981,1992,0,max(y)]) xlabel('Years') ylabel('aids cases') legend(['Data','Logistic Fit'])