Question

The table shows the population P (in millions) of the United States from 1800 to 1870 where t represents the number of years i need 13,14 and 15 please
0 0
Add a comment Improve this question Transcribed image text
Answer #1

SOLUTION:

12.

Note: Since the student has not asked for question 12, I have taken the liberty of using a Matlab code instead of a graphing calculator. Hope that is okay.

Please find the code for fitting attached below.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%This code fits time vs population data into exponential and logistic
%models

%time
t=0:10:70;
t=t';

P=[5.3,7.2,9.6,12.9,17.0,23.2,31.4,39.8]'; %population

f=fit(t,P,'exp1'); %exponential fitting and plotting
disp(f);
figure(1);
plot(f,t,P);
xlabel('Time in years from 1800');
ylabel('Population in millions');
title('Exponential model');

[ Qpre, D, sm, varcov] = fit_logistic(t,P); %logistic fitting
tfit=0:1:70;
Plogifit=D(2)./(1 + exp(-D(3)*(tfit-D(1))));%finding the fit data
%plotting
disp(D);
figure(2);
scatter(t,P);
hold on
plot(tfit,Plogifit);
xlabel('Time in years from 1800');
ylabel('Population in millions');
title('Logistic model');
legend('data','fitted model');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%This open source code is downloaded from https://in.mathworks.com/matlabcentral/fileexchange/41781-fit_logistic-t-q

function [ Qpre, p, sm, varcov] = fit_logistic(t,Q)
%fit a logistic function to time series Q(t).
% Inputs: t (time),Q (time series variable)
% Outputs: Qpre (logistic model fit to data) and
% p is 3 element vector containing parameters describing the logistic:
% thalf, Qinf, and alpha
% Q(t) = Qinf/(1 + exp(-alpha*(t-thalf)))
% thalf is symmetric inflection point
% Qinf is value as t --> infinity
% alpha is time decay constant
% sm is 3 element vector giving 1-sigma confidence limits of parameters
% e.g., thalf = p(1) +/- sm(1)
% simply double the values in sm to get 95% confidence limits
% varcov is the complete 3x3 variance-covariance matrix for investigating
% how model paramters co-vary with each other.
% sm is sqrt(diag(varcov))
%
% Example:
% Qinf = 10.2; alpha = 0.33; thalf = 108.5;
% t = 100:120;
% Q = Qinf./(1 + exp(-alpha*(t-thalf)));
% noise = randn(1,length(t));
% Qd = Q+noise;
% Qpre = fit_logistic(t,Qd);
% figure(1)
% clf
% hold on
% plot(t,Qd,'o') % data
% plot(t,Qpre) % best fitting logistic
%   
% Written by James Conder, Southern Illinois University, Oct. 2010
% Cleaned up for publishing May 16, 2013
% May 17, 2013: Allow for decreasing logistic.
% May 23, 2013: Fix instability when using short
% or long absolute times (relative to alpha = 1).
% May 28, 2013: added example in comments, fixed an introduced bug
% from May 23 edit.
% Feb 12, 2014: Revisited occasional flatlining problem.
% (Qpre goes to mean).
% Made initial alpha more robust. Scaled to time rather than simply
% defaulting to one (removes much of need for rescaling time).
% Added check for flatlining. If occurs, reset seeds with larger
% alpha and start over.
% Jan 25, 2016: calculate confidence limits for parameters


% equations are set up to solve for an increasing logistic.
% Check if decreasing and if so, reverse time
[~,I] = sort(t);
reverse_t = false;
if sum(diff(Q(I))) < 0 % decreasing in time
reverse_t = true;
t = -t;
end

% stretch short or long sequences in time to stabilize alpha
tstretch = [];
if max(t)-min(t) < 1.e-4 || max(t)-min(t) > 1e5;
tstretch = 1./(max(t) - min(t));
t = t*tstretch;
end

% initial guesses for parameters
thalf = 0.5*(min(t) + max(t));
Qinf = max(Q);
alpha = 1./(max(t)-min(t)); alphareset = alpha;

flipQ = false;
if isrow(Q)
flipQ = true; % expecting a column vector. flip if row.
t = t';
Q = Q';
end

itermax = 1000 ;   % number of maximum iterations
epsilon = 1;

ii = 0 ; % initialize counter
thresh = 1.e-6 ; % threshold to stop iterating
G = zeros(length(t),3) ; % dimensionalize partial derivative matrix

while epsilon > thresh
ii = ii + 1 ;
Qpre = Qinf./(1 + exp(-alpha*(t-thalf))) ; % 'predicted' data
if max(Qpre) - min(Qpre) == 0
% if Qpre flatlines, "a" likely needed to be seeded higher
% (sharper climb)
alphareset = 2*alphareset;
thalf = 0.5*(min(t) + max(t));
Qinf = max(Q);
alpha = alphareset;
Qpre = Qinf./(1 + exp(-alpha*(t-thalf))) ;
end
d = Q - Qpre ; % data vector (predicted - observed)

% linearized partial derivatives
ee = min(exp(-alpha*(t-thalf)),1.e12) ;
eee = 1./((1 + ee).^2) ;
G(:,1) = -Qinf*alpha*(ee.*eee) ; % dd/dthalf
G(:,2) = 1./(1 + ee) ; % dd/dQinf
G(:,3) = Qinf*(t-thalf).*(ee.*eee) ; % dd/dalpha
  
[U,S,V] = svd(G,0);               % Singular Value Decomposition
Sinvdiag = 1./diag(S) ;
ising = Sinvdiag(1)./Sinvdiag < 1.e-12 ;
Sinvdiag(ising) = 0;
Sinv = diag(Sinvdiag);
dm = 0.1*V*Sinv*U'*d;
                          
% get new parameters: m = m0 + dm
thalf = thalf + dm(1);
Qinf = Qinf + dm(2);
alpha = alpha + dm(3);                 
                                         
epsilon = norm(dm);
if ii > itermax
   disp('max number of iterations reached...exiting')
disp(['normalized epsilon: ' num2str(epsilon/thresh)])
epsilon = thresh ;
end
end
Qpre = Qinf./(1 + exp(-alpha*(t-thalf))) ; % 'predicted' data

if ~isempty(tstretch)
thalf = thalf/tstretch;
alpha = alpha*tstretch;
end
if reverse_t % decreasing logistic
thalf = -thalf;
alpha = -alpha;
end

if flipQ
Qpre = Qpre';
Q = Q'; % necessary for a posteriori variance
end
p = [ thalf Qinf alpha ];

%%% find confidence bounds for parameters (1-sigma)
if nargout > 2
sd = sum((Q-Qpre).^2)/(length(Q)-3); % a posteriori variance
varcov = sd*sd*inv(G'*G); % model variance-covariance matrix
sm = sqrt(diag(varcov)); % model variance
end

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

By running the code, we get the models and their graphs as given below:

  1. Exponential model: P-5.539e(00284%
  2. Logistic model: 186.4511 186.4511 1+ є-0. -1 + 35.3673e_00324t 0324*(t-110.0006)

Exponential model 45 data fitted curve 40 35 30 c 25 20 15 10 5 0 10 20 30 40 50 60 70 Time in years from 1800

Logistic model 45 O data fitted model 40 35 30 c 25 20 15 10 5 0 10 20 30 40 50 60 70 Time in years from 1800

13, 14:

Exponential mod re k= 5.539 bt ou Fn P= 92 milion 92 0 0284 5.53 1- I8. 9428 Jn year, adding 1800 1898.9 스 18 o2 mn.

Loalskc Model we have ound that ot 1 +ae Whrre186- 4511 a 35.3673 Now I ae aYe 2 af In /a C-

Tor P- a2 milon 35, 3673 Kaz 0,032千 8 G.452 · 109.2636 t In vears, adding 860 1 Year -909.2 1gog Tu the logitic mod gives val

15:

Date ae GİYEn- that arowth ataims is z In(a) Το shsu: 잇 γス But C 2 2 2. a.

NOTE: IN Q15, IT IS GIVEN THAT y = c/2 WHEN THE GROWTH IS MAXIMUM IN THE LOGISTIC MODEL. AS A BONUS, THIS IS SHOWN IN THE FOLLOWING PAGES:

PONUS PROOF: To sho that outh is mxmum n ant 2 la Foi «routh dyldi) to be moximum ere d 01 t ae ←双 - 82 s ae

In a t ae au 2

PLEASE GIVE A POSITIVE RATING IF YOU LIKE MY ANSWER. THANK YOU!

Add a comment
Know the answer?
Add Answer to:
The table shows the population P (in millions) of the United States from 1800 to 1870 where t rep...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT