# Solve 2 sides of equation with SymPy

I have the following equation to calculate the boundary inductance in an electronic circuit. With SymPy, I can use Lb.evalf(subs={...}) to calculate Lb value when I have D, f and R.

Lb = ((1-D)**2*D*R)/(2*f)

Without having to re-arrange the equation, is there a way to solve for D, f or R if a supply Lb value? For example, I know all the value in the equation, except for D.

## Answers

You can use sympy to solve for the variables. For example:

import sympy from sympy.abc import d,f,r,l equation = sympy.Eq( ((1-d)**2*d*r)/(2*f), l ) print sympy.solve(equation,"f") print sympy.solve(equation,"r") print sympy.solve(equation,"d")

This gives the equation analytically solved for in terms of f and r respectively.

[d*r*(d - 1)**2/(2*l)] [2*f*l/(d*(d - 1)**2)]

Note that solving for d results in a mess of solutions. This is expected since the equation is cubic in d.

[-(-1/2 - sqrt(3)*I/2)*(-f*l/r + sqrt((-2*f*l/r + 2/27)**2/4 - 1/729) + 1/27)**(1/3) + 2/3 - 1/(9*(-1/2 - sqrt(3)*I/2)*(-f*l/r + sqrt((-2*f*l/r + 2/27)**2/4 - 1/729) + 1/27)**(1/3)), -(-1/2 + sqrt(3)*I/2)*(-f*l/r + sqrt((-2*f*l/r + 2/27)**2/4 - 1/729) + 1/27)**(1/3) + 2/3 - 1/(9*(-1/2 + sqrt(3)*I/2)*(-f*l/r + sqrt((-2*f*l/r + 2/27)**2/4 - 1/729) + 1/27)**(1/3)), -(-f*l/r + sqrt((-2*f*l/r + 2/27)**2/4 - 1/729) + 1/27)**(1/3) + 2/3 - 1/(9*(-f*l/r + sqrt((-2*f*l/r + 2/27)**2/4 - 1/729) + 1/27)**(1/3))]