In this tutorial, we discuss how to solve the problems from the topics like limits, derivatives, and Taylor's series expansion using SymPy.

other basic math function

Computing Limits

SymPy can compute symbolic limits with the limit function. We use the following syntax

Compute the limits of the following: $$\lim_{x\rightarrow \pi} \sin (x/2 +\sin(x))$$

$$\lim_{x\rightarrow 0^+}{2e^{1/x}\over e^{1/x}+1} $$
$$\lim_{x\rightarrow\infty}{\cos x-1\over x}$$

Exercise:

  1. Find $\displaystyle \lim_{x\rightarrow 0}\Big({\sqrt{1-\cos 2x}\over\sqrt{2}x}\Big)$
  2. Find $\displaystyle\lim_{x\rightarrow 0}x^4\sin({\pi\over 4})$

Derivatives

$${d\over dx}\Big({1+\sin x\over 1-\cos x}\Big)^2$$
$${d\over dx}(\log_5(x))^{x/2}$$
$${d\over dx}f(x+g(x))$$

Higher Derivatives

$${d^2\over dx^2}e^{x^4}$$
$${\partial^7\over \partial x\partial y^2\partial z^4}e^{xyz}$$

Exercise:

  1. Find the 5th derivative of $(2x+5)$
  2. Compute the derivative of $\log(4x^2-1)$
  3. Compute the derivative of ${x+3\over (x-1)(x+2)}$
  4. Compute the derivative of $x^2\log3x$

Taylor's Series:

Any smooth function $f(x)$ can be approximated by using series expansion. The Taylor's series of the function $f(x)$ at $x=x_0$ is $$ f(x)=f(x_0) + {(x-x_0)f'(x_0)\over 1!}+ {(x-x_0)^2f"(x_0)\over 2!}+\cdots+\infty $$ The series expansion at $x_0=0$ is known as Maclaurin's series.

Series Expansion

SymPy can compute asymptotic series expansions of functions around a point. To compute the expansion of $f(x)$ around the point $x=x_0$ terms of order $x^n.$ The following sytax will give the series expansion.

  f(x).series(x,x0,n)

By default x0=0 and n=6

All $x$ terms with power greater than or equal to $x^8$ are omitted.

Taylor's series of the function $e^x$ about $x=1.$

Exercise:

  1. Expand $log(1+\sin^2x)$ in powers of $x$ as far as the term in $x^6.$
  2. Expand $\log_e x$ about $x=1.$
  3. Expand $e^{x\sin x}$ about $x=0.$