Last active
August 4, 2020 10:09
-
-
Save noppoMan/12af7afc688d1d6e070d0b2b508d8956 to your computer and use it in GitHub Desktop.
Cauchy sequence - https://note.com/noppoman/n/ne938ba48e1d5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from matplotlib import pyplot as plt | |
import sympy as sym | |
from IPython.display import display, Math | |
x, n, m = sym.symbols('x, n, m') | |
expn = sym.sin(x)**2 | |
f = lambda n: sym.expand_trig(expn)/n | |
F = lambda f: sym.Integral(f, (x, 0, 2)) | |
display(Math("f_n(x) = "+ sym.latex(f(n)))) | |
display(Math("\|f_m - f_n\| = "+ sym.latex(F(f(n) - f(m))))) | |
epsilons = [] | |
distances = [] | |
n_range = np.arange(1, 301, 2) | |
m_range = np.arange(2, 301, 2) | |
for n, m in zip(n_range, m_range): | |
epsilon = np.sqrt(1.189/n**2 + 1.189/m**2) | |
d = F(f(n) - f(m)).evalf() | |
epsilons.append(epsilon) | |
distances.append(d) | |
plt.figure(figsize=(12, 6)) | |
plt.plot(n_range, distances) | |
plt.plot(n_range, epsilons, alpha=0.7) | |
plt.xlabel('n') | |
plt.ylabel('value') | |
plt.legend(['‖f_m - f_n‖', 'epsilon'], prop={'size': 15}) | |
plt.show() | |
plt.figure(figsize=(12, 6)) | |
plt.plot(n_range[100:], distances[100:]) | |
plt.xlabel('n') | |
plt.ylabel('value') | |
plt.plot(n_range[100:], epsilons[100:], alpha=0.7) | |
plt.title("n, m > 200") | |
plt.legend(['‖f_m - f_n‖', 'epsilon'], prop={'size': 15}) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment