#!/usr/bin/env python # coding: utf-8 # ### Homework 3 # # David Allemang. STOR 881.001.FA25. # # Verify that for all $x > 0$ and $\lambda \in \mathbb R$, $$\lim_{\lambda \to 0} \frac{x^\lambda - 1}{\lambda} = \ln x$$ # Proof. Apply L'Hôpital's rule: $$\lim_{\lambda \to 0} \frac f g = \lim_{\lambda \to 0} \frac {f_\lambda}{g_\lambda}$$ where $f = x^\lambda - 1$ and $g = \lambda$. # # $$\begin{align*} # \lim_{\lambda \to 0} \frac{x^\lambda - 1}{\lambda} &= # \lim_{\lambda \to 0} \frac{x^\lambda \ln x - 0}{1} \\ # &= x^0 \ln x \\ # &= \ln x # \end{align*}$$ # Just for fun, let's plot the thing. # In[1]: import matplotlib.pyplot as plt from matplotlib.colors import Normalize import numpy as np x = 2 ** np.linspace(-2, 2, 50) l = np.linspace(-1, 1, 21) l = l[l != 0] X, L = np.meshgrid(x, l) Z = (X ** L - 1) / L cmap = plt.get_cmap('bwr') lnorm = Normalize(l.min(), l.max()) # In[2]: plt.figure(figsize=(9, 6)) plt.title("Box-Cox transform (linear scale)") lines = plt.plot(x, Z.T, lw=1.5, ls='-') lines[0].set_label(rf'$\lambda = {l.min()}$') lines[-1].set_label(rf'$\lambda = {l.max()}$') for line, color in zip(lines, cmap(lnorm(l))): line.set_color(color) line, = plt.plot(x, np.log(x), lw=3, ls=':', c='k') line.set_label(r'$\ln x$') plt.legend() plt.show(); # In[3]: plt.figure(figsize=(9, 6)) plt.title("Box-Cox transform (log scale)") plt.gca().set_xscale('log', base=2) lines = plt.plot(x, Z.T, lw=1.5, ls='-') lines[0].set_label(rf'$\lambda = {l.min()}$') lines[-1].set_label(rf'$\lambda = {l.max()}$') for line, color in zip(lines, cmap(lnorm(l))): line.set_color(color) line, = plt.plot(x, np.log(x), lw=3, ls=':', c='k') line.set_label(r'$\ln x$') plt.legend() plt.show();