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
JavaScript
x
7
1
from sympy import *
2
3
w, a, x, g = symbols('w a x, g', real=True)
4
lhs = 1/g*(w-a)**g
5
rhs = 1/(2*g)*(w-x)**g + 1/(2*g)*(w+x)**g
6
solve((lhs,rhs), (x,g,w))
7
But this seems to be trying to solve for a numerical answer.
Advertisement
Answer
You can create a 2-sided equation with Eq
:
JavaScript
1
7
1
In [52]: Eq(lhs, rhs)
2
Out[52]:
3
g g g
4
(-a + w) (w - x) (w + x)
5
───────── = ──────── + ────────
6
g 2⋅g 2⋅g
7
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
:
JavaScript
1
7
1
In [53]: solve(Eq(lhs, rhs), a)
2
Out[53]:
3
⎡ -1 ⎤
4
⎢ ─── _____________________⎥
5
⎢ g g ╱ g g ⎥
6
⎣w - 2 ⋅╲╱ (w - x) + (w + x) ⎦
7