This article covers how to compute symbolic differentiation in python. Symbolic differentiation refers to the differentiation of mathematical expression with variables. Computing symbolic differentiation in python can be carried out using the SymPy module.

To compute the differentiation, first, let’s define a simple mathematical expression,

# importing sympy from sympy import * # declaring symbolic variables x = symbols('x') # declaring the expression expr = x**2 print("Before Differentiation:") display(expr)

Now, we use the sympy.diff() function to compute the first-order derivative of the expression with respect to x

# computing derivative derv = diff(expr) print("After Differentiation :") display(derv)

The sympy.diff() function can also be used to compute partial differentiation for multivariable functions as shown below,

# importing sympy from sympy import * # declaring symbolic variables x,y = symbols('x y') # declaring the expression expr = 2*x*y # differentiation with respect to x derv_x = diff(expr, x) # differentiation with respect to y derv_y = diff(expr, y) print("Before differentiation: ") display(expr) print("After differentiation with respect to x:") display(derv_x) print("After differentiation with respect to y:") display(derv_y)

## In Conclusion:

This is how you can compute differentiation in python. If you have any queries regarding this tutorial, do comment below!