Created
December 24, 2016 18:35
-
-
Save alekseyl1992/7d59ef9da0be8e7405879732d594df61 to your computer and use it in GitHub Desktop.
This file contains 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
%matplotlib inline | |
import numpy as np | |
import matplotlib.pyplot as plt | |
xs = np.arange(-100, 100, 0.1) | |
ys = np.sin(xs) | |
n = 75 | |
def mcloren(x): | |
result = 0 | |
for i in range(n): | |
result += (-1)**i * (x**(2*i + 1)) / np.math.factorial(2*i + 1) | |
return result | |
def mult(x): | |
result = x | |
for i in range(n-1): | |
result *= 1 - (x / ((i+1) * np.pi)) ** 2 | |
return result | |
ys_mc = np.vectorize(mcloren)(xs) | |
ys_mp = np.vectorize(mult)(xs) | |
plt.ylim(ymin=-2, ymax=2) | |
plt.plot(xs, ys) | |
plt.plot(xs, ys_mc) | |
plt.plot(xs, ys_mp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment