Reputation: 3374
I have a complicated equation which is function of several variables and I want to manipulate like this example:
y = (x + a) / z
x = y*z - a
Is it possible to do this kind of manipulation matlab or python?
If there is possibility then please point out method or function to do this operation.
I tried following code in Sympy Shell:
x,y,z,a = symbols ('x y z a')
solve ( y = (x-a)/z, x)
I am getting following error:
Traceback (most recent call last):
File "<string>", line 1
SyntaxError: non-keyword arg after keyword arg
Upvotes: 0
Views: 607
Reputation: 91580
SymPy is a Python library, so your SymPy code needs to be valid Python. In Python, =
is the assignment operator, which is why solve ( y = (x-a)/z, x)
gives a SyntaxError. See http://docs.sympy.org/latest/gotchas.html#equals-signs.
To create an equality in SymPy use Eq
, like solve(Eq(y, (x - a)/z, x)
, or use the fact that expressions in SymPy are assumed to be equal to zero, like solve(y - (x - a)/z, x)
.
Upvotes: 1
Reputation: 45752
In Matlab you'd need the symbolic math toolbox (which I don't have so I can't test) and then you should be able to do use the solve
function:
syms y x a z
solve(y == (x+a)/z, x)
I have NO experince with sympy
but pretty sure based on the docs this is how you do it:
from sympy import solve, Poly, Eq, Function, exp
from sympy.abc import x, y, z, a
solve(y - (x+a)/z, x)
Upvotes: 2