Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Project: The following table lists April 1 population estimates for the United S

ID: 3283301 • Letter: P

Question

Project: The following table lists April 1 population estimates for the United States from 1940 to 2000 Year 940 1950 1960 1970 1980 1990 2000 Population (in millions) 131.954 151.326 179.323 203.302 226.546249.306 281.422 Programming: a) Write a program from scratch allowing the user to enter population data and to compute the appropriate interpolating polynomial for the complete data set (degree six polynomial for these seven data points). You may decide how much freedom you wish to give the user (e.g., can the user choose how many data points to enter?) You can use whatever programming language or software package you would like as long as you are doing this from scratch (you cannot use a built-in polynomial interpolation command). b) Use your program to estimate the U.S. population in the years 1930, 1975, and 2010. Plot your interpolating polynomial on the interval 1900 to 2020 c) Look up the estimated U.S. population for the years 1930, 1975, and 2010. How well does your polynomial estimate the actual population values? Discuss the results and why you think it is turning out the way it did. What modifications would you make?

Explanation / Answer

Solution;

1.The solution (part a)

% Taking inputs from user

years = input("Enter the data for year variable")

population = input("Enter the data for population variable")

plot(years, population)

new_years = [1930 1975 2010]

% Part b

% For polyfit I have chosen the degree as 2 which is best fit in this case.

% You can see this if you plot the data on XY plane, it's almost linear.

coeffs = polyfit(years, population, 2)

val = polyval(coeffs, new_years)

disp(val);

% Part c

% Plotting the population from year 19000 to 2020

x = linspace(1900, 2020, 10)

y = polyval(coeffs, x)

plot(x, y)

2.Part 2

These are the population values for the years [1930 1975 2010] (using the polynomial degree of 2)

109.67   214.05   307.26

3.Part 3

So, If we use the polynomial degree of 6 for polyfit method we get the following values for the years [1930 1975 2010] –

Which is not correct as the value for year 1930 is 200.12 but in the sample input data for year 1940 population is 131.954. So, the value for 1930 must be less than 131.954.

Therefore, if we change the polynomial degree to 2, we get more accurate data