MATLAB Answers

Matlab fitting image is inconsistent with the parametric equation

2 views (last 30 days)
Albert Zhang
Albert Zhang on 20 Jul 2021
Answered: Star Strider on 20 Jul 2021
I used the Curve Fitting Toolbox to make a polynomial (degree 3) . But Matlab fitting image is inconsistent with the parametric equation.
My data
year=[1750 1800 1850 1900 1950 1990 2000 2009];
population(millions)=[791 980 1260 1650 2520 5270 6060 6800];
cftool(year,population);
I want to forecast population in 1987.
then I made image by Curve Fitting Toolbox.
if I find the point by image
the population is 4458
But if I used the results from the Curve Fitting Toolbox
f(x) = p1*x^3 + p2*x^2 + p3*x + p4
p1 = 0.001021
p2 = -5.604
p3 = 1.026e+04
p4 = -6.254e+06
when x=1980, f(x)=16281
as you can see 16281 is much bigger than 4458
I want to know why and how can I change it
THANK YOU!!!!!!!!!

Answers (1)

Star Strider
Star Strider on 20 Jul 2021
Try this —
year=[1750 1800 1850 1900 1950 1990 2000 2009];
% population(millions)=[791 980 1260 1650 2520 5270 6060 6800];
population = [791 980 1260 1650 2520 5270 6060 6800]*1E+6;
f = fit(year(:), population(:), 'poly3')
Warning: Equation is badly conditioned. Remove repeated data points or try centering and scaling.
f =
Linear model Poly3: f(x) = p1*x^3 + p2*x^2 + p3*x + p4 Coefficients (with 95% confidence bounds): p1 = 1021 (491.5, 1550) p2 = -5.604e+06 (-8.589e+06, -2.62e+06) p3 = 1.026e+10 (4.651e+09, 1.586e+10) p4 = -6.254e+12 (-9.758e+12, -2.75e+12)
figure
plot(f, year, population, 'p')
grid
hl = legend;
hl.Location = 'best';
text(1980, f(1980), sprintf('1980 Population (Est) = %4.0fx10^6 \\rightarrow', f(1980)*1E-6), 'Horiz','right', 'Vert','middle')
.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by