Last active
August 29, 2015 14:15
-
-
Save FilipDominec/eae584ca5ab3476c4160 to your computer and use it in GitHub Desktop.
- or, how eˣ can be approximated by fractions having small degrees of numerator/denominator
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
#!/usr/bin/env python | |
#-*- coding: utf-8 -*- | |
## Import common moduli | |
from __future__ import division | |
import matplotlib, sys, os, time | |
import matplotlib.pyplot as plt | |
import numpy as np | |
from scipy.constants import c, hbar, pi | |
## Use LaTeX | |
matplotlib.rc('text', usetex=True) | |
matplotlib.rc('font', size=8) | |
matplotlib.rc('text.latex', preamble = '\usepackage{amsmath}, \usepackage{yfonts}, \usepackage{txfonts}, \usepackage{lmodern},') | |
x=np.linspace(-1,3, 100) | |
plt.plot(x,np.exp(x), c='k') | |
# m = 0 | |
plt.plot(x,(1)/(np.ones_like(x)) , c='r', alpha=1) | |
plt.plot(x,(1)/(1 - x) , c='r', alpha=.7) | |
plt.plot(x,(1)/(1 - x + (1/2)*x**2) , c='r', alpha=.4) | |
plt.plot(x,(1)/(1 - x + (1/2)*x**2 - (1/6)*x**3), c='r', alpha=.2) | |
# m = 1 | |
plt.plot(x,(1 + x)/(1) , c='g', alpha=1) | |
plt.plot(x,(1 + (1/2)*x)/(1 - (1/2)*x) , c='g', alpha=.7) | |
plt.plot(x,(1 + (1/3)*x)/(1 - (2)/(3)*x + (1)/(6)*x**2) , c='g', alpha=.5) | |
plt.plot(x,(1 + (1/4)*x)/(1 - (3/4)*x + (1)/(4)*x**2 - (1/24)*x**3), c='g', alpha=.4) | |
# m = 3 | |
plt.plot(x,(1 + x + (1/2)*x**2 + (1)/(6)*x**3)/(1) , c='b', alpha=1) | |
plt.plot(x,(1 + (3/4)*x + (1)/(4)*x**2 + (1/24)*x**3)/(1 - (1/4)*x) , c='b', alpha=.7) | |
plt.plot(x,(1 + (3/5)*x + (3)/(20)*x**2 + (1)/(60)*x**3)/(1 - (2/5)*x + (1/20)*x**2) , c='b', alpha=.5) | |
plt.plot(x,(1 + (1/2)*x + (1)/(10)*x**2 + (1)/(120)*x**3)/(1 - (3/7)*x + (1)/(10)*x**2 - (1)/(120)*x**3), c='b', alpha=.4) | |
# m = 4 | |
plt.plot(x,(1 + x + (1/2)*x**2 + (1)/(6)*x**3+ (1/24)*x**4)/(1) , c='c', alpha=1) | |
plt.plot(x,(1 + (4/5)*x + (3/10)*x**2 + (1)/(15)*x**3+ (1)/(120)*x**4)/(1 - (1/5)*x) , c='c', alpha=.7) | |
plt.plot(x,(1 + (2/3)*x + (1/5)*x**2 + (1)/(30)*x**3+ (1)/(360)*x**4)/(1 - (1/3)*x + (1)/(30)*x**2) , c='c', alpha=.5) | |
plt.plot(x,(1 + (4/7)*x + (1/7)*x**2 + (2)/(105)*x**3+ (1)/(840)*x**4)/(1 - (3/7)*x + (1)/(14)*x**2 - (1/210)*x**3), c='c', alpha=.4) | |
## Simple axes | |
plt.ylim((-1,5)); plt.yscale('linear') | |
#plt.xlim((-0.1,1.1)); plt.xscale('linear') | |
## ==== Outputting ==== | |
## Finish the plot + save | |
plt.xlabel(u"x"); | |
plt.ylabel(u"y"); | |
plt.grid() | |
plt.legend(prop={'size':10}, loc='upper right') | |
plt.savefig("output.png", bbox_inches='tight') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment