Generate 10 points equally spaced along a sine curve in the interval `[0,4*pi]`

.

Use `polyfit`

to fit a 7th-degree polynomial to the points.

Evaluate the polynomial on a finer grid and plot the results.

Create a vector of 5 equally spaced points in the interval `[0,1]`

, and evaluate
at those points.

Fit a polynomial of degree 4 to the 5 points. In general, for `n`

points, you can fit a polynomial of degree `n-1`

to exactly pass through the points.

Evaluate the original function and the polynomial fit on a finer grid of points between 0 and 2.

Plot the function values and the polynomial fit in the wider interval `[0,2]`

, with the points used to obtain the polynomial fit highlighted as circles. The polynomial fit is good in the original `[0,1]`

interval, but quickly diverges from the fitted function outside of that interval.

First generate a vector of `x`

points, equally spaced in the interval `[0,2.5]`

, and then evaluate `erf(x)`

at those points.

Determine the coefficients of the approximating polynomial of degree 6.

p =
0.0084 -0.0983 0.4217 -0.7435 0.1471 1.1064 0.0004

To see how good the fit is, evaluate the polynomial at the data points and generate a table showing the data, fit, and error.

T =
X Y Fit FitError
___ _______ __________ ___________
0 0 0.00044117 -0.00044117
0.1 0.11246 0.11185 0.00060836
0.2 0.2227 0.22231 0.00039189
0.3 0.32863 0.32872 -9.7429e-05
0.4 0.42839 0.4288 -0.00040661
0.5 0.5205 0.52093 -0.00042568
0.6 0.60386 0.60408 -0.00022824
0.7 0.6778 0.67775 4.6383e-05
0.8 0.7421 0.74183 0.00026992
0.9 0.79691 0.79654 0.00036515
1 0.8427 0.84238 0.0003164
1.1 0.88021 0.88005 0.00015948
1.2 0.91031 0.91035 -3.9919e-05
1.3 0.93401 0.93422 -0.000211
1.4 0.95229 0.95258 -0.00029933
1.5 0.96611 0.96639 -0.00028097
1.6 0.97635 0.97652 -0.00016704
1.7 0.98379 0.98379 8.3306e-07
1.8 0.98909 0.98893 0.00016278
1.9 0.99279 0.99253 0.00025791
2 0.99532 0.99508 0.00024347
2.1 0.99702 0.99691 0.0001131
2.2 0.99814 0.99823 -8.8548e-05
2.3 0.99886 0.99911 -0.00025673
2.4 0.99931 0.99954 -0.00022451
2.5 0.99959 0.99936 0.00023151

In this interval, the interpolated values and the actual values agree fairly closely. Create a plot to show how outside this interval, the extrapolated values quickly diverge from the actual data.

Create a table of population data for the years 1750 - 2000 and plot the data points.

T =
year pop
____ _________
1750 7.91e+08
1775 8.56e+08
1800 9.78e+08
1825 1.05e+09
1850 1.262e+09
1875 1.544e+09
1900 1.65e+09
1925 2.532e+09
1950 6.122e+09
1975 8.17e+09
2000 1.156e+10

Use `polyfit`

with three outputs to fit a 5th-degree polynomial using centering and scaling, which improves the numerical properties of the problem. `polyfit`

centers the data in `year`

at 0 and scales it to have a standard deviation of 1, which avoids an ill-conditioned Vandermonde matrix in the fit calculation.

Use `polyval`

with four inputs to evaluate `p`

with the scaled years, `(year-mu(1))/mu(2)`

. Plot the results against the original years.