Python | sympy.diff() method
With the help of sympy.diff() method, we can find the differentiation of mathematical expressions in the form of variables by using sympy.diff() method.
Syntax :
sympy.diff(expression, reference variable)
Return : Return differentiation of mathematical expression.
Example #1 :
In this example we can see that by using sympy.diff() method, we can find the differentiation of mathematical expression with variables. Here we use symbols() method also to declare a variable as symbol.
# import sympy from sympy import * x, y = symbols('x y') gfg_exp = x + y exp = sympy.expand(gfg_exp**2) print("Before Differentiation : {}".format(exp)) # Use sympy.diff() method dif = diff(exp, x) print("After Differentiation : {}".format(dif)) |
Output :
Before Differentiation : x**2 + 2*x*y + y**2
After Differentiation : 2*x + 2*y
Example #2 :
# import sympy from sympy import * x, y = symbols('x y') gfg_exp = sin(x)*cos(x) print("Before Differentiation : {}".format(gfg_exp)) # Use sympy.diff() method dif = diff(gfg_exp, x) print("After Differentiation : {}".format(dif)) |
Output :
Before Differentiation : sin(x)*cos(x)
After Differentiation : -sin(x)**2 + cos(x)**2
Recommended Posts:
- class method vs static method in Python
- Python | set() method
- Python | next() method
- Python | os.dup() method
- Python | os.fstatvfs() method
- Python | PyTorch cos() method
- Python | os.statvfs() method
- Python | PyTorch tan() method
- Python | os.set_inheritable() method
- Python | sympy.Pow() method
- Python | os.ttyname() method
- Python | os.isatty() method
- Python | os.device_encoding() method
- Python | os.get_inheritable() method
- Python | os.getloadavg() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




