Exercises 24.4 Homework
1.
Following Example 24.2.3, plot an approximating cubic spline for the data \((k, \tan^{-1} k)\text{,}\) \(k=-5, -4, \dots, 5\text{.}\) For comparison, also plot the actual function \(y=\tan^{-1} x\) on the interval \([-5, 5]\text{.}\) How accurate is the approximation? Plot the difference of the spline and arctangent to answer this question.
(Recall that arctangent is atan
in Matlab.)
2.
Let us revisit Example 3.2.1, changing it to the following.
k = 2; A = rand(k, 1e7) - 1/2; S = sum(A, 1); histogram(S, 100, 'Normalization', 'pdf')
(If using Octave where histogram
is not available, replace the last line with hist(S, 100, 100/k)
.)
This produces a normalized histogram of \(10^7\) sample sums, with \(k\) numbers in each sample. The numbers are chosen from uniform distribution on \([-1/2, 1/2]\text{.}\) Normalization means that the area under the histogram is 1 (in probability terms, this histogram approximates the probability density function of sample sums, hence the option “pdf”.)
What should the value \(k\) be in order for the histogram to resemble the cardinal B-spline of degree 3 shown in Figure 24.2.1? Find the answer experimentally after trying a few values of \(k\text{.}\) Having found a suitable \(k\text{,}\) confirm your guess by adding the graph of the cardinal spline to the histogram plot (recall hold on
/ hold off
are useful for combining graphs.)