Taylor Expansion¶

Using the same formula for real numbers, the Taylor expansion formula can be applied complex functions. A complex regular function can be expressed uniquely as following power series.

$$ \begin{align} f(z)&=\sum^\infty_{n=0} {f^{(n)}(a)\over n!}(z-a)^n\\ &=f(a)+f'(a)(z-a)+{f''(a)\over 2!}(z-a)^2+{f'''(a)\over 3!}(z-a)^3+\cdots \end{align} $$

Let us calculate the Taylor expansion of $ f(z)=e^z $ around $ z=1 $.

In [ ]:
from sympy import symbols, series, exp, I

z = symbols("z")
series(exp(z), z, 1, 5)
Out[ ]:
$\displaystyle e + e \left(z - 1\right) + \frac{e \left(z - 1\right)^{2}}{2} + \frac{e \left(z - 1\right)^{3}}{6} + \frac{e \left(z - 1\right)^{4}}{24} + O\left(\left(z - 1\right)^{5}; z\rightarrow 1\right)$

Let us calculate the Taylor expansion of $ f(z)=z^2 $ around $ z=i $.

In [ ]:
series(z**2,z,I,5)
Out[ ]:
$\displaystyle \left(z - i\right)^{2} + 2 i \left(z - i\right) - 1$

Here is the case with $ f(z)={1\over z-2i}$ around $ z=0 $.

In [ ]:
series(1/(z-2*I),z,0,5)
Out[ ]:
$\displaystyle \frac{i}{2} + \frac{z}{4} - \frac{i z^{2}}{8} - \frac{z^{3}}{16} + \frac{i z^{4}}{32} + O\left(z^{5}\right)$

In case with non-regular function with isolated singularities, Laurent series can be used that include negative terms of the series.

$$ f(z)=\sum^\infty_{n=-\infty} {f^{(n)}(a)\over n!}(z-a)^n $$

The series() function can be used for Laurent series. The following calculates the Laurent series of the function that includes the negative terms.

$$ f(z)={e^z\over z^2} $$

In [ ]:
z = symbols("z")
f = exp(z) / z**2
series(f, z, 0, 5)
Out[ ]:
$\displaystyle \frac{1}{z^{2}} + \frac{1}{z} + \frac{1}{2} + \frac{z}{6} + \frac{z^{2}}{24} + \frac{z^{3}}{120} + \frac{z^{4}}{720} + O\left(z^{5}\right)$

Let us calculate the Laurent series of the following function using series().

$$ f(z)={\cos(z)\over z^2} $$

In [ ]:
from sympy import cos


f = cos(z) / z**2
series(f, z, 0, 5)
Out[ ]:
$\displaystyle \frac{1}{z^{2}} - \frac{1}{2} + \frac{z^{2}}{24} - \frac{z^{4}}{720} + O\left(z^{5}\right)$

The 'series()' does not calculate the following function. First, convert $e^z$ to power series then use subs() and replace $z$ with ${1\over z}$.

$$ f(z)=e^{1\over z} $$

In [ ]:
f = exp(1 / z)
g = series(exp(z), z, 0, 5)
g.subs(z, 1 / z)
Out[ ]:
$\displaystyle \frac{1}{24 z^{4}} + \frac{1}{6 z^{3}} + \frac{1}{2 z^{2}} + \frac{1}{z} + 1 + O\left(\frac{1}{z^{5}}; z\rightarrow \infty\right)$