Shareddiff-functions.sagewsOpen in CoCalc
Author: Harald Schilly
Views : 23

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)
b(x)xa(x)+a(x)xb(x)\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))
6b(x)xb(x)+2xa(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))
2xD0(a)(t2+b(x2))D0(b)(x2)\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)
(a(x)2b(x))3b(2a(x))2\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))
4(a(x)2b(x))3xa(x)D0(b)(2a(x))b(2a(x))3+3(a(x)2b(x))2(xa(x)2xb(x))b(2a(x))2\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}}