Python | sympy.collect() method
With the help of sympy.collect() method, we are able to collect the mathematical expressions having same power.
Syntax :
sympy.collect()
Return : Return mathematical expression having same powers.
Example #1 :
In this example, we can see that by using sympy.collect() method, all the same powers of variables are collected together as a same mathematical expression.
# import sympy from sympy import * x, y, z = symbols('x y z') gfg_exp = x * y + x - 3 + 2 * x**2 - z * x**2 + x**3 # Using sympy.collect() method gfg_exp = collect(gfg_exp, x) print(gfg_exp) |
Output :
x**3 + x**2*(2 – z) + x*(y + 1) – 3
Example #2 :
# import sympy from sympy import * x, y, z = symbols('x y z') gfg_exp = x * x + x - 3 + 2 * z**2 - y * x**2 + x**3 # Using sympy.collect() method gfg_exp = collect(gfg_exp, x) print(gfg_exp) |
Output :
x**3 + x**2*(1 – y) + x + 2*z**2 – 3
Recommended Posts:
- class method vs static method in Python
- Python | os.dup() method
- Python | next() method
- Python | set() method
- Python | os.setgroups() method
- Python | os.ftruncate() method
- Python | os.set_blocking() method
- Python | sympy.Pow() method
- Python | os.kill() method
- Python | os.fchmod() method
- Python | os.unlink() method
- Python PIL | GaussianBlur() method
- Python | os.fstat() method
- Python | os.times() method
- Python | bytes() 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.



