Python | sympy.as_independent () method

Python Methods and Functions

Using the sympy.as_independent() method, we can independently separate the mathematical expression by the variable passed as a parameter to sympy.as_independent () .

Syntax: sympy.as_independent(variable)

Return: Return a tuple having separated variables in mathematical expression.

Example # 1:
In this example, we can see that using sympy. as_independent () we can split the math function based on the independent variable that is passed as a parameter.

# import sympy

from sympy import *  

  

 

x, y = symbols ( ' xy' )

 
# Use the sympy.as_independent (variable) method

gfg = ( 1 + 2 * x + 1 / x) .as_independent (x)

 

print (gfg)

Output:

(1, 2 * x + 1 / x)

Example # 2:

# import sympy

from sympy import *  

  

x, y = symbols ( 'xy' )

 
# Use the sympy.as_independent (variable) method

gfg = ( 1 / y * * 2 + x) .as_independent (y )

  

print (gfg)

Output:

(x, y ** (- 2) )





Get Solution for free from DataCamp guru