CSCI3656: NUMERICAL COMPUTATION Homework 9 solution

$35.00

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (1 vote)

1. Consider the function
f(x) = sin(2πx) + cos(3πx), x ∈ [−1, 1]. (1)
Compute the coefficients of a least-squares-fit degree-7 polynomial from n = 33 evenly spaced
points. In other words, your training data are pairs (xi
, yi) with i = 1, . . . , 33 where the xi
’s are
evenly spaced points in [−1, 1] (like, linspace) and yi = f(xi). Make a plot of both f(x) and
the degree-7 polynomial approximation.
2. Create testing data by (i) choosing 100 random points in the interval [−1, 1] and (ii) evaluating
the function at each of those points. This gives you a new set of data (x
0
1
, y0
1
), . . . ,(x
0
100, y0
100).
For d from 1 to 31, compute the least-squares coefficients of a polynomial of degree d with the
same training data as in the last problem using both the QR method and the normal equations.
For each trained polynomial pd(x), compute the normalized testing error:
ed =
P100
i=1(y
0
i − p(x
0
i
))2
P100
i=1(y
0
i
)
2
!1/2
(2)
Plot the error ed versus d on a log scale (that is, use semilogy). Make sure to include both (i)
the error computed using the QR decomposition and (ii) the error computed using the normal
equations. Interpret the error behavior.
BONUS (50 POINTS): Here some US COVID case counts from back in March.
Days since Feb 29 Case count
1 89
2 105
3 125
4 159
5 227
6 331
7 444
8 564
9 728
10 1000
11 1267
12 1645
13 2204
14 2826
15 3485
17 7038
1
Derive the linear least-squares system whose solution contains the coefficients of a log-linear model for
case count over time. Plot the data on top of the model on a log scale. How well does the log-linear
model (which represents exponential growth) appear to model the growth in the case count? What
was the case doubling time over this roughly two week period?
2