In [5]:
import numpy as np
import sympy as sp
import matplotlib.pyplot as plt
%matplotlib inline
import pi_sequences as p3
import boundary_layer_func1 as p1
import sequence_limits as p2
import diffeq_midpoint as p4
import math
Michael Seaman
The following sequences all converge to pi, although at different rates.
In order: $$a_n = 4\sum_{k=1}^{n}\frac{(-1)^{k+1}}{2k-1}$$
$$b_n = (6\sum_{k=1}^{n}k^{-2})^{1/2} $$$$c_n = (90\sum_{k=1}^{n}k^{-4})^{1/4} $$$$d_n = \frac{6}{\sqrt{3}}\sum_{k=0}^{n}\frac{(-1)^{k}}{3^k(2k+1)}$$$$e_n = 16\sum_{k=0}^{n}\frac{(-1)^{k}}{5^{2k+1}(2k+1)} - 4\sum_{k=0}^{n}\frac{(-1)^{k}}{239^{2k+1}(2k+1)}$$
In [5]:
n = 30
plt.plot([x for x in range(n)],p3.pi_sequence(n, p3.fa),'g.')
plt.show()
In [6]:
plt.plot([x for x in range(n)],p3.pi_sequence(n, p3.fb) ** .5 ,'b.')
plt.show()
In [7]:
plt.plot([x for x in range(n)],p3.pi_sequence(n, p3.fc) ** .25 ,'y.')
plt.show()
In [8]:
plt.plot([x for x in range(n)],p3.pi_sequence(n, p3.fd),'r.')
plt.show()
In [9]:
plt.plot([x for x in range(n)],p3.pi_sequence(n, p3.fd),'c.')
plt.show()
In [10]:
n = 10
plt.plot([x + 20 for x in range(n)],p3.pi_sequence(n + 20, p3.fa)[-n:],'g.')
plt.plot([x + 20 for x in range(n)],(p3.pi_sequence(n + 20, p3.fb) ** .5)[-n:] ,'b.')
plt.plot([x + 20 for x in range(n)],(p3.pi_sequence(n + 20, p3.fc) ** .25)[-n:] ,'y.')
plt.plot([x + 20 for x in range(n)],p3.pi_sequence(n + 20, p3.fd)[-n:],'r.')
plt.plot([x + 20 for x in range(n)],p3.pi_sequence(n + 20, p3.fd)[-n:],'c.')
plt.plot((20, 30), (math.pi, math.pi), 'b')
plt.show()
In [11]:
x = np.linspace(0,1,10000)
y1 = p1.v(x, 1, np.exp)[2]
y2 = p1.v(x, 0.1, np.exp)[2]
y3 = p1.v(x, 0.01, np.exp)[2]
fig = plt.figure(1)
plt.plot(x, y1, 'b')
plt.plot(x, y2, 'r')
plt.plot(x, y3, 'g')
plt.xlabel('x')
plt.ylabel('v(x)')
plt.legend(['(1 - exp(x / mu)) / (1 - exp(1 / mu))'])
plt.axis([x[0], x[-1], min(y3), max(y3)])
plt.title('Math Function')
plt.show(fig)
Computes and returns the following sequence for N = 100
$$a_n = \frac{7+1/(n+1)}{3-1/(n+1)^2}, \qquad n=0,1,2,\ldots,N$$
In [2]:
p2.part_a()
In [2]:
p2.part_b()
In [3]:
p2.part_c()
In [2]:
p2.part_d()
In [3]:
p2.part_e()
In [3]:
p2.part_f()
In [6]:
function_call = p4.vector_midpoint(p4.np.sin, 0, p4.np.pi, 10000)
print function_call[1][-1]
Observe the close adherance to the actual value of this cannonical value.
We can also call it at a different value of x. Let's look at the value of this integral from 0 to pi over 2. Again, the result will have strikingly close adherance to the analytical value of this integral.
In [7]:
print function_call[1][5000]
In [ ]: