$24
Consider the parameterized family of functions,
f (x) =
1
; x 2 [ 5; 5]:
1 + exp( x)
The parameter controls how smooth f is near x = 0, as shown:
1
0.9
0.8
0.7
0.6
( )X
0.5
θ
F
0.4
0.3
0.2
θ=1
0.1
θ=2
θ=10
0
-5
0
5
X
To start this homework, let = 1.
1. Generate training data: Create a vector with n = 7 evenly spaced points in the interval [ 5; 5]. (In Matlab, you can do this with linspace.) For each point xi in this vector, compute yi = f (xi). You should now have 7 pairs (xi; yi). Provide a printout of the 7 pairs (e.g., in a table).
2. Train the model: Construct the Vandermonde system and solve for the coe cients of the unique degree 6 interpolating polynomial p6(x). Provide a printout of the 6 coe cients.
3. Generate testing data: Create a new vector with 101 evenly spaced points in [ 5; 5]. For each point x0i, compute yi0 = f (x0i). Report the mean (mean in Matlab) and standard deviation (std in Matlab) from the set of points y10; : : : ; y1010.
4. Compute the testing error: Compute and report the the absolute testing error:
error = error
= maximum
j
y0
p
(x0)
j
=1;n=7
1
i
101
i
6
i
1
Note that the error depends on the value of and the number of training points / the degree of the polynomial.
5. Repeat steps 1-4 with = 10. How does the error change? What does that tell you about the quality of the polynomial approximation for the two functions?
6. EXTRA CREDIT (15pts): Repeat steps 1-4 with = 10 and n = 8; 9; : : : ; 15. Plot error =10;n versus n on a semilog scale. How does the polynomial approximation converge as n increases?
2