Predicting Population Growth in 1900 with Stewart 275/05

AI Thread Summary
The discussion revolves around using MATLAB for population modeling through exponential fitting. A user is seeking guidance on extracting the y-value for a specific x-value (x=3) after performing a polynomial fit on population data. The conversation highlights differences in approach, with one user opting for a linear fit instead of a quadratic one, as suggested in the original problem. They also mention simplifying the process by focusing solely on exponential fitting as per instructions from a referenced website. The user shares their MATLAB code, which includes multiple segments for different time periods and populations, demonstrating how to plot the data and fit curves accordingly. The emphasis is on understanding how to manipulate the code to achieve the desired output while addressing the specific requirements of the problem.
xpack
Messages
37
Reaction score
0
muhaag.jpg


I have this
Code:
delete s275x05.txt; diary s275x05.txt
clear; clc; close all; echo on
%
% Stewart 275/05
%
year=[0:1]; % n+1 = year + 50
pop=[728 906];
p=polyfit(year,log(pop),2)
plot(year,pop,'o','MarkerFaceColor','r')
hold on
x=[0:0.01:6];
y=exp(polyval(p,x));
plot(x,y)
hold on
%part a
%popluation at year 1900
x1900=3
%
echo off; diary off

What I am stuck at is how do I say I want the y value when x = 3?
 
Physics news on Phys.org
i just got finished with that problem, and mine is a little bit different than yours. for instance, on the polyfit lines, you don't need to make them quadratic, i just made mine linear. also, i didn't do parts a b and c because on the website (http://calclab.math.tamu.edu/~dmanuel/calclab/m151/Fall/2009c_matlab8.html) all it says is to use exponential fitting on the pairs of points. so it's a lot simpler than you're making it out to be. all in all, i got this:

'delete s275x05.txt; diary s275x05.txt
clear; clc; close all; echo on

year=[0:1];
pop=[728 906];
p=polyfit(year,log(pop),1)
plot(year,pop,'o','MarkerFaceColor','r')
hold on
x=[0:0.01:6];
y=exp(polyval(p,x));
plot(x,y)
hold off

year=[2:3];
pop=[1171 1608]
p=polyfit(year,log(pop),1)
plot(year,pop,'o','MarkerFaceColor','r')
hold on
x=[0:0.01:6];
y=exp(polyval(p,x));
plot(x,y)
hold off

year=[3:4];
pop=[1608 2517];
p=polyfit(year,log(pop),1)
plot(year,pop,'o','MarkerFaceColor','r')
hold on
x=[0:0.01:6];
y=exp(polyval(p,x));
plot(x,y)
hold off

year=[0:4];
pop=[728 906 1171 1608 2517];
p=polyfit(year,log(pop),1)
plot(year,pop,'o','MarkerFaceColor','r')
hold on
x=[0:0.01:6];
y=exp(polyval(p,x));
plot(x,y)
hold off

echo off; diary off'
 
Back
Top