Mathematics | ![]() ![]() |
Error Bounds
Error bounds are useful for determining if your data is reasonably modeled by the fit. An optional second output parameter can be obtained from polyfit
and passed as an input parameter to polyval
in order to obtain the error bounds.
For example, the code below uses polyfit
and polyval
to produce error bounds for a second-order polynomial model. Year values are normalized. This code uses an interval of ±2, corresponding to a 95% confidence interval.
[p2,S2] = polyfit(sdate,pop,2);
[pop2,del2] = polyval(p2,sdate,S2);
plot(cdate,pop,'+',cdate,pop2,'g-',cdate,pop2+2*del2,'r:',...
cdate,pop2-2*del2,'r:'), grid on
![]() | Exponential Fit | The Basic Fitting Interface | ![]() |