What is the graph of Rudin's 7.18 function

50 Views Asked by At

Code borrowed from here

Theorem 7.18 from Baby Rudin:

There exists a real continuous function on the real line which is nowhere differentiable.

proof

Define $$\tag{34} \varphi(x) = \lvert x \rvert \qquad \qquad (-1 \leq x \leq 1) $$ and extend the definition of $\varphi(x)$ to all real $x$ by requiring that $$ \tag{35} \varphi(x+2) = \varphi(x). $$ Then, for all $s$ and $t$, $$\tag{36} \lvert \varphi(s) - \varphi(t) \rvert \leq \lvert s-t \rvert. $$ In particular, $\varphi$ is continuous on $\mathbb{R}^1$. Define $$ \tag{37} f(x) = \sum_{n=0}^\infty \left( \frac{3}{4} \right)^n \varphi \left( 4^n x \right). $$ Since $0 \leq \varphi \leq 1$, Theorem 7.10 shows that the series (37) converges uniformly on $\mathbb{R}^1$. By Theorem 7.12, $f$ is continuous on $\mathbb{R}^1$. Now fix a real number $x$ and a positive integer $m$. Put $$ \tag{38} \delta_m = \pm \frac{1}{2} \cdot 4^{-m} $$ where the sign is so chosen that no integer lies between $4^m x$ and $4^m \left( x + \delta_m \right)$. This can be done, since $4^m \left\lvert \delta_m \right\rvert = \frac{1}{2}$. Define $$ \tag{39} \gamma_n = \frac{ \varphi \left( 4^n \left( x + \delta_m \right) \right) - \varphi \left( 4^n x \right) }{ \delta_m }. $$ When $n > m$, then $4^n \delta_m$ is an even integer, so that $\gamma_n = 0$. When $0 \leq n \leq m$, (36) implies that $\left\lvert \gamma_n \right\rvert \leq 4^n$. Since $\left\lvert \gamma_m \right\rvert = 4^m$, we conclude that $$ \begin{align} \left\lvert \frac{ f \left( x + \delta_m \right) - f(x) }{ \delta_m } \right\rvert &= \left\lvert \sum_{n=0}^m \left( \frac{3}{4} \right)^n \gamma_n \right\rvert \\ &\geq 3^m - \sum_{n=0}^{m-1} 3^n \\ &= \frac{1}{2} \left( 3^m + 1 \right). \end{align} $$ As $m \to \infty$, $\gamma_m \to 0$. It follows that $f$ is not differentiable at $x$.

I want to see the graph of $f(x)$ I don't have the tools that graph such functions

1

There are 1 best solutions below

6
On BEST ANSWER

This is the function after summing the first 25 terms in the series.

This is the function after summing the first 25 terms in the series.

And this is the function as we sum from 1 to 15 terms.

And this is the function as we sum from 1 to 15 terms.

Here is the code to generate it:

import numpy as np
import matplotlib.pyplot as plt

from matplotlib.animation import FuncAnimation

def phi(x):
    return np.abs(x % 2 - 1)

def f(x, num_terms=25):
    n = np.arange(num_terms)[:, np.newaxis]
    terms = (3/4)**n * phi(4**n * x)
    return np.sum(terms, axis=0)

# Generate x values
x = np.linspace(-2, 2, 100000)

# Create a figure and axis
fig, ax = plt.subplots(figsize=(8, 6))

# Initialize the plot
line, = ax.plot([], [])

# Set up the plot properties
ax.set_xlim(-2, 2)
ax.set_ylim(0, 5)
ax.set_xlabel('x')
ax.set_ylabel('f(x)')
ax.grid(True)

# Update function for the animation
def update(i):
    y = f(x, i+1)
    line.set_data(x, y)
    ax.set_title(f'Visualization of f(x) with {i+1} terms')
    return line,

# Create the animation
anim = FuncAnimation(fig, update, frames=15, interval=500, blit=True)

# Save the animation as a GIF
anim.save('f(x)_animation.gif', writer='pillow')

# Show the plot
plt.show()