4

I am having a bit of trouble with Sympy's solveset. I am trying to use Sympy to find a solution to an basic circuit analysis question involving three unknown resistors and two equations. I realize that I will have to guess at the value of one of the resistors and then calculate the value of the other two resistors. I am using superposition to solve the circuit.

This is the circuit and superposition I am trying to solve

import sympy
V_outa, V_outb, R_1, R_2, R_3, V_1, V_2 = symbols('V_outa V_outb R_1 R_2 R_3 V_1 V_2')

### Here are a bunch of variable definitions. 
R_eq12 = R_2*R_3/(R_2+R_3)
R_eq123 = R_eq12 + R_1
V_outa = V_1 *R_eq12/R_eq123

R_eq13 = R_1*R_3/(R_1+R_3)
R_eq123b = R_2 + R_eq13
V_outb = V_2 * R_eq13/R_eq123b

### Here is my governing equation. 
V_out = 0.5* V_outb + (1/6) *V_outa

### Now I can start setting up the equations to solve. This sets the 
### coefficient of the V1 term equal to the 1/2 in the governing equation
### and the coefficient of the V2 term equal to 1/6. I have also guessed
### that R_3 is equal to 10 ohms. 
eq1 = Eq(1.0/2.0, V_out.coeff(V_2).subs(R_3, 10))
eq2 = Eq(1.0/6.0, V_out.coeff(V_2).subs(R_3, 10))

#### Now when I try to solve eq1 and eq2 with solveset, I get an error. 
solveset([eq1, eq2], (R_2, R_3))

And here is the error I get:

ValueError: [Eq(0.500000000000000, 10*R_1/((R_1 + 10)*(10*R_1/(R_1 + 10) + R_2))), Eq(0.166666666666667, 10*R_1/((R_1 + 10)*(10*R_1/(R_1 + 10) + R_2)))] is not a valid SymPy expression

The other thing I don't understand is the set type I get when I try to solve it this way. Could someone also explain what set type this is, and how to make use of it?

expr3 = -1.0/2.0 + V_out.coeff(V_2).subs(R_3, 10)
solveset(expr3, R_2)

A screen shot of the weird set type

Any help would be much appreciated. I know it is a solvable set because Wolfram Alpha had no problems with it.

Thanks! David

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Foggy
  • 383
  • 2
  • 12
  • 2
    As stated in the [docs](http://docs.sympy.org/latest/modules/solvers/solveset.html#what-will-you-do-with-the-old-solve), `solveset` cannot handle (yet) non-linear multivariate equations. Use `solve` instead. – Stelios Apr 04 '17 at 07:45
  • @Stelios - Thanks for the guidance. I think I tried `solve` as well and still had issues... I will go back and try again. Can you help me understand the set type shown in the 2nd screen shot? – Foggy Apr 05 '17 at 09:25
  • The system `[eq1, eq2]`, as written in the OP, makes no sense, that's probably why `solve` fails. The `solveset` output in the case of `expr3` seems to be a bug. Using `solve` instead of `solveset` in this case works. – Stelios Apr 05 '17 at 09:49
  • I opened an [issue](https://github.com/sympy/sympy/issues/12494#issuecomment-291881306) and as was informed, the notation returned by `solveset` in the second case states that the solution is `0`, noting that if `R_2` equals the element of the second set by default the ratio is undefined. – Stelios Apr 05 '17 at 14:53
  • @Stelios Is there a good place that summarizes all the solveset conditional outputs? Wolfram Alpha makes it pretty easy to read these sorts of solution constraints. – Foggy Apr 06 '17 at 10:26

0 Answers0