PushkarKadam
PushkarKadam

Reputation: 339

How to solve the equation for LHS value in python

I'm trying to solve the following equation using sympy library.

I = -0.53V + 65.88

I have been using the following line of code:

from sympy import *
V = Symbol('vi')
I = -0.5*vi + 65.88
solve(V - 5, I)

But, it returns me an empty list. I am aware that this code was designed for finding the unknown on RHS, but I don't know the syntax for finding the unknown value on the LHS.

Upvotes: 0

Views: 700

Answers (1)

Hugh Bothwell
Hugh Bothwell

Reputation: 56654

Defining I that way makes it an Addition, not a Symbol; you can evaluate it but not solve in terms of it (see Equals signs in the Sympy docs).

Instead try

import sympy as sp

# create the symbols
V, I = sp.Symbols("V I")

# set up an equality statement
eq = sp.Eq(I, sp.Float("-0.53") * V + sp.Float("65.88"))

# try to reorder the equation to find solutions for V
sp.solve(eq, V)   # returns a single solution,  [-1.88679245283019*I + 124.301886792453]

# solve numerically for V == 5
eq.subs(V, sp.Float("5"))   # returns Eq(I, 63.2300000000000)

Upvotes: 1

Related Questions