Edit or run this notebook

HW 2 for CS 4220

You may (and probably should) talk about problems with the each other, with the TAs, and with me, providing attribution for any good ideas you might get. Your final write-up should be your own.

219 μs
289 μs
58.6 ms
2.8 s

1: Box-Cox

The Box-Cox family of transformations is sometimes used in statistics to normalize non-negative data. The transformation has the form

gλ(x)={xλ1λ,λ0log(x),λ=0

The obvious implementation in Julia is

209 μs
box_cox1 (generic function with 1 method)
353 μs

Unfortunately, this is prone to large errors when |λlogx|1, as we can see from a simple plot.

247 μs
1.3 s

Explain why, and suggest an alternative with better error in this case, coded in the function box_cox2. You may wish to use the function expm1 in your solution (though there are other approaches as well).

183 μs
box_cox2 (generic function with 1 method)
335 μs

If you have done this right, you should be able to recreate the plot above without the numerical artifact for small λ values. You may find it useful to also use a log scale for the y axis.

149 μs
471 μs

2: Pi, see!

The following routine estimates π by recursively computing the semiperimeter of a sequence of 2k+1-gons embedded in the unit circle.

164 μs
pi_estimator1 (generic function with 1 method)
831 μs

Unfortunately, something goes catastrophically wrong with this computation in floating point.

126 μs
96.8 ms

Explain what goes wrong in this computation in floating point, and rewrite the problematic formula in pi_estimator2 to avoid the issue.

136 μs
pi_estimator2 (generic function with 1 method)
821 μs
492 μs

3: Norm!

Let L:PdPd+1 be defined by

(Lp)(t)=0tp(x)dx

In this exercise, we will consider the L1([1,1]), L([1,1]), and L2([1,1]) norms on the spaces Pd; recall these are

p1=11|p(x)|dx

p=max1x1|p(x)|

p2=11|p(x)|2dx

You may also find it useful to recall that

|abp(x)dx|ab|p(x)|dx

17.1 ms

L1 case

Argue that for the norm induced by the L1 norm on Pd, we have L11. You do not need to cite any regularity results to change the order of integration (everything is nice enough that the relevant results hold).

3.7 ms
L case

Argue that for the norm induced by the L norm on Pd, we have L1.

5.5 ms
L2 case

For the L2 case, we will express write a matrix A for the operator L with respect to the normalized Legendre polynomials {qj(x)}j=0d, which form an orthonormal basis for Pd (you can take my word for this). In particular, this means that if p(x)=j=0dajqj(x), then p2=j=0daj2, and similarly if Lp(t)=j=0d+1bjqj(t) then Lp2=j=0dbj2.

Explain why the facts above imply that L2=A2.

It turns out that as d, the norm of the associated L operator increases monotonically (and very rapidly) to a limit. Using the following Julia code for the matrix A as a function of the polynomial degree d, give an estimate of that limit. This part does not need to be rigourous – I am asking for a computational experiment! You may find it useful to use the Julia opnorm function.

(You do not need to understand the Julia code to form A, but it is probably within your grasp to do so if you are curious – the Wikipedia article on Legendre polynomials has all the relevant information!)

379 μs
Lmatrix (generic function with 1 method)
1.3 ms
Loading...
ii