Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SymPy - Solving for variable in equation

Tags:

python

sympy

Is it possible to define an equation and solve a variable in that equation?

D_PWM, Rsense, A = symbols('D_PWM, Rsense, A')

i_out = D_PWM * (A/Rsense)

print i_out

solve(i_out, Rsense)

Result:

A*D_PWM/Rsense
[]
like image 635
Diego Aguilera Avatar asked Oct 14 '16 16:10

Diego Aguilera


People also ask

How do you solve a system of equations using SymPy?

After the symbols and equations are defined, we can use SymPy's solve() function to compute the value of x and y. The first argument passed to the solve() function is a tuple of the two equations (eq1, eq2) . The second argument passed to the solve() function is a tuple of the variables we want to solve for (x, y) .

How do you evaluate a SymPy expression?

To evaluate a numerical expression into a floating point number, use evalf . SymPy can evaluate floating point expressions to arbitrary precision. By default, 15 digits of precision are used, but you can pass any number as the argument to evalf .


1 Answers

i_out has not been declared as a symbol.

>>> from sympy import *
>>> var('D_PWM, Rsense, A i_out')
(D_PWM, Rsense, A, i_out)
>>> eqn=Eq(i_out,D_PWM * (A/Rsense))
>>> solve(eqn,Rsense)
[A*D_PWM/i_out]
like image 95
Bill Bell Avatar answered Sep 19 '22 01:09

Bill Bell