Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import matplotlib.pyplot as plt
- def p_valuation(p, n):
- if n == 0:
- return math.inf
- result = 0
- while n % p == 0: # Note that "%" is the modulo operation
- n = n / p
- result += 1
- return result
- def p_norm(p, n):
- return p ** (- p_valuation(p, n)) # Note that "**" is exponentiation
- index = 1
- def plot_convergence(ax, sequence, limit, p, name):
- global index
- distances = [p_norm(p, element - limit) for element in sequence]
- ax.plot(range(len(sequence)), distances)
- ax.set_title(str(index))
- index += 1
- N = 20
- P = 2
- fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, constrained_layout=True )
- plot_convergence(ax1, [P ** n for n in range(N)], 0, P, "p_power")
- plot_convergence(ax2, [(P + 1) ** n for n in range(N)], 1, P, "non_p_power")
- plot_convergence(ax3, [sum([P ** i for i in range(n)]) for n in range(N)], -1, P, "power_series")
- plot_convergence(ax4, [math.factorial(n) for n in range(N)], 0, P, "factorial")
- plt.savefig("plots.png")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement