MATLAB Answers

find the values of polynomial to use polyfit

11 views (last 30 days)
By using the census population data, Show that the relationship results between t and the log of the population by setting . To find and , you use the code of polyfit,
where this data is fitted in the form of
So, let's define population as p
Since ,
And log of p is
load census
t = (cdate - 1790)/10;
lnp = @(c) log(c(2)) + c(3)*t;
polyfit( lnp, t)
I write this code to find c(2) and c(3). But this code does not work. I get error.


Sign in to comment.

Accepted Answer

Cris LaPierre
Cris LaPierre on 26 Mar 2020
With polyfit, you supply it the X and Y data and it returns the equation for you. Well, the coefficients of the polynomial of the order you specify. The error message you are getting is becaue you are trying to pass in an anonymous function for X.


Cris LaPierre
Cris LaPierre on 27 Mar 2020
I knew you could do it! Nice job.
Once you have the coefficients captured in p, you can use polyval to compare the fit to the original.
load census
p = polyfit(cdate,log(pop),1)
% generate fit line
% visualize
Zeynep  Toprak
Zeynep Toprak on 27 Mar 2020
wow, perfect thank you so much for your great effort!! You're the best! Take care! :)
Zeynep  Toprak
Zeynep Toprak on 28 Mar 2020
Hello professor again, yesterday, you explained this question perfectly. these are not assigments. since classes are closed down, on these leisure times, I try to improve my matlab skills by myself by following videos on youtube and solving some exercises. i have one more question. i solved it mostly. but at the end i need to solve two nonlinear equation simutanously. bu i could not here. Or can i do question with fminsearch ? My question is here if you 're going to help me one more, i will be glad. :)

Sign in to comment.

More Answers (0)

Sign in to answer this question.