CoCalc Shared Filesdiff-functions.sagews
Author: Harald Schilly
Views : 86

Differentiating functions in SageMath

http://doc.sagemath.org/html/en/tutorial/tour_algebra.html#solving-differential-equations

x = var('x')
a = function('a')(x)
b = function('b')(x)
ab1 = diff(a * b, x)
show(ab1)

$\displaystyle b\left(x\right) \frac{\partial}{\partial x}a\left(x\right) + a\left(x\right) \frac{\partial}{\partial x}b\left(x\right)$
show(diff(2 * a + 3 * b^2, x))

$\displaystyle 6 \, b\left(x\right) \frac{\partial}{\partial x}b\left(x\right) + 2 \, \frac{\partial}{\partial x}a\left(x\right)$
# chain rule.
# be explicit about what x is, i.e. a(x= ... )
t = var('t')
show(diff(a(x = t^2 + b(x = x^2)), x))

$\displaystyle 2 \, x \mathrm{D}_{0}\left(a\right)\left(t^{2} + b\left(x^{2}\right)\right) \mathrm{D}_{0}\left(b\right)\left(x^{2}\right)$
ex3 = (a - 2*b)^3 / (b(x = 2*a(x=x)))^2
show(ex3)

$\displaystyle \frac{{\left(a\left(x\right) - 2 \, b\left(x\right)\right)}^{3}}{b\left(2 \, a\left(x\right)\right)^{2}}$
show(diff(ex3, x))

$\displaystyle -\frac{4 \, {\left(a\left(x\right) - 2 \, b\left(x\right)\right)}^{3} \frac{\partial}{\partial x}a\left(x\right) \mathrm{D}_{0}\left(b\right)\left(2 \, a\left(x\right)\right)}{b\left(2 \, a\left(x\right)\right)^{3}} + \frac{3 \, {\left(a\left(x\right) - 2 \, b\left(x\right)\right)}^{2} {\left(\frac{\partial}{\partial x}a\left(x\right) - 2 \, \frac{\partial}{\partial x}b\left(x\right)\right)}}{b\left(2 \, a\left(x\right)\right)^{2}}$