<jupyter_start><jupyter_text>---author: <NAME> (<EMAIL>)---This answer assumes you have imported SymPy as follows.<jupyter_code>from sympy import *                   # load all math functions
init_printing( use_latex='mathjax' )  # use pretty math output<jupyter_output><empty_output><jupyter_text>Let's define an example function whose Taylor series we'd like to compute.<jupyter_code>var( 'x' )
formula = exp( 2*x + 1 )
formula<jupyter_output><empty_output><jupyter_text>Let's ask for a degree-5 Taylor series centered at $x=2$.  From the code below,you can tell that the third parameter is the center point and the fourthparameter is the degree.<jupyter_code>series( formula, x, 2, 5 )<jupyter_output><empty_output><jupyter_text>The final term (starting with O---oh, not zero) means that there are more termsin the infinite Taylor series not shown in this finite approximation.If you want to show just the approximation, you can tell it to remove the O term.<jupyter_code>series( formula, x, 2, 5 ).removeO()<jupyter_output><empty_output><jupyter_text>You can also compute individual coefficients in a Taylor seriesby remembering the formula for the $n^\text{th}$ term in the series and applying it,as follows.  The formula for a series centered on $x=a$ is $\frac{f^{(n)}(a)}{n!}$.From the answer above, we can see that the coefficient on the $n=3$ term is $\frac43e^5$.<jupyter_code>n = 3
a = 2
diff( formula, x, n ).subs( x, a ) / factorial( n )<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10465901417960838, 'fraction_numerical': 0.009453072248480757, 'mean_word_length': 5.253164556962025, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '195728', 'license': 'MIT', 'n_tokens_mistral': 476, 'n_tokens_neox': 458, 'n_words': 179, 'path': 'database/tasks/How to compute the Taylor series for a function/Python, using SymPy.ipynb', 'repo_name': 'nathancarter/how2data', 'size': '1500'}