Skip to content

Instantly share code, notes, and snippets.

@alekseyl1992
Created December 24, 2016 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alekseyl1992/7d59ef9da0be8e7405879732d594df61 to your computer and use it in GitHub Desktop.
Save alekseyl1992/7d59ef9da0be8e7405879732d594df61 to your computer and use it in GitHub Desktop.
%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