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))]

Need Your Help

How do I allow a user to post an item directly to their facebook wall?

facebook facebook-graph-api facebook-sharer

I'm creating a site that has images and video behind a login. I'd like the user to be able to share an asset but the can't share the url since you have to be logged in to see it. I know I can creat...

React Native Touchable is disabling ScrollView

scrollview react-native

I'm new to React Native, so am probably asking something very obvious, but please help.