Reputation: 1978
I'd like to use sympy to solve he following equation in terms of x, g, and w.
Here's what I thought I should code
from sympy import *
w, a, x, g = symbols('w a x, g', real=True)
lhs = 1/g*(w-a)**g
rhs = 1/(2*g)*(w-x)**g + 1/(2*g)*(w+x)**g
solve((lhs,rhs), (x,g,w))
But this seems to be trying to solve for a numerical answer.
Upvotes: 0
Views: 575
Reputation: 14470
You can create a 2-sided equation with Eq
:
In [52]: Eq(lhs, rhs)
Out[52]:
g g g
(-a + w) (w - x) (w + x)
───────── = ──────── + ────────
g 2⋅g 2⋅g
When you say that you want to solve "in terms of x, g and w" I'm not sure I understand what you mean. Do you mean that you want to solve for a
in terms of the others? If so then you just have to ask to solve for a
:
In [53]: solve(Eq(lhs, rhs), a)
Out[53]:
⎡ -1 ⎤
⎢ ─── _____________________⎥
⎢ g g ╱ g g ⎥
⎣w - 2 ⋅╲╱ (w - x) + (w + x) ⎦
Upvotes: 1
Reputation: 11209
Well, you need to be aware of sympy limitations. It might not be able to tackle this type of equation. As far as being two sided, make it one sided by solving rhs - lhs = 0
.
Plugging your equation into WolframAlpha did not solve it. As such, greatly doubt sympy will give you anything useful.
Upvotes: 1