How
Contents
How#
Calculate the derivative of an expression.#
You can calculate the derivative of an expression using sympy.diff
which takes, an expression, a variable and a degree.
Usage
sympy.diff(expression, variable, degree=1)
The default value of degree
is 1.
For example to compute \(\frac{d (4 x ^ 3 + 2 x + 1}{dx}\):
import sympy as sym
x = sym.Symbol("x")
expression = 4 * x ** 3 + 2 * x + 1
sym.diff(expression, x)
To compute the second derivative: \(\frac{d ^ 2 (4 x ^ 3 + 2 x + 1}{dx ^ 2}\)
sym.diff(expression, x, 2)
Calculate the indefinite integral of an expression.#
You can calculate the indefinite integral of an expression using
sympy.integrate
. Which takes an expression and a variable.
Usage
sympy.integrate(expression, variable)
For example to compute \(\int 4x^3 + 2x + 1 dx\):
sym.integrate(expression, x)
Calculate the definite integral of an expression.#
You can calculate the definite integral of an expression using
sympy.integrate
. The first argument is an expression but instead of
passing a variable as the second argument you pass a tuple with the
variable as well as the upper and lower bounds of integration.
Usage
sympy.integrate(expression, (variable, lower_bound, upper_bound))
For example to compute \(\int_0^4 4x^3 + 2x + 1 dx\):
sym.integrate(expression, (x, 0, 4))
Use \(\infty\)#
In sympy
we can access \(\infty\) using sym.oo
:
Usage
sympy.oo
For example:
sym.oo
Calculate limits of an expression#
You can calculate using sympy.limit
. The first argument is the
expression, then the variable and finally the expression the variable
tends to.
Usage
sympy.limit(expression, variable, value)
For example to compute \(\lim_{h \to 0} \frac{4 x ^ 3 + 2 x + 1 - 4(x - h)^3 - 2(x - h) - 1}{h}\):
h = sym.Symbol("h")
expression = (4 * x ** 3 + 2 * x + 1 - 4 * (x - h) ** 3 - 2 * (x - h) - 1) / h
sym.limit(expression, h, 0)