Appreciate any help for solving my equations system #25780
-
I have been playing the Sympy for a day and need to figure out a way to derive the equation for x1 with many probability variables ρ as shown in the image. Given the equation system with variable x1,..,x5 and p1,...,p5, I can represent them as "sympy.symbols" in Sympy, but I am wondering whether it is possible to use the "solve" function provided by Sympy library to derive the result for x1. In the problem I need to solve, x1 can be represented by ρ like the one shown in the image. Unfortunately for me, the examples in the tutorial do not seem to cover this kind of transitive and intertwined variable isolation. I am really struggling, so I appreciate any hint or tip. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I don't really understand what are the inputs and outputs in this calculation. Just seeing the equations in the image does not make it clear what is happening. What would be the equations that you would start with and what would be the equation or expression that you would want to end up with? |
Beta Was this translation helpful? Give feedback.
-
This is just a system of 5 linear equations for 5 unknowns. You can use In [9]: x1, x2, x3, x4, x5 = symbols('x1:6')
In [10]: r1, r2, r3, r4, r5 = symbols('rho1:6')
In [11]: eqs = [
...: Eq(x5, 1),
...: Eq(x4, x3),
...: Eq(x3, r2*x2 + r4*x4),
...: Eq(x2, r3*x3 + r5*x5),
...: Eq(x1, r1*x2),
...: ]
In [12]: sols = solve(eqs, [x1, x2, x3, x4, x5], dict=True)
In [14]: sols
Out[14]:
⎡⎧ ρ₁⋅ρ₄⋅ρ₅ - ρ₁⋅ρ₅ ρ₄⋅ρ₅ - ρ₅ -ρ₂⋅ρ₅ -ρ₂⋅ρ₅ ⎫⎤
⎢⎨x₁: ────────────────, x₂: ──────────────, x₃: ──────────────, x₄: ──────────────, x₅: 1⎬⎥
⎣⎩ ρ₂⋅ρ₃ + ρ₄ - 1 ρ₂⋅ρ₃ + ρ₄ - 1 ρ₂⋅ρ₃ + ρ₄ - 1 ρ₂⋅ρ₃ + ρ₄ - 1 ⎭⎦
In [13]: sols[0][x1]
Out[13]:
ρ₁⋅ρ₄⋅ρ₅ - ρ₁⋅ρ₅
────────────────
ρ₂⋅ρ₃ + ρ₄ - 1 |
Beta Was this translation helpful? Give feedback.
This is just a system of 5 linear equations for 5 unknowns. You can use
solve
to solve the equations and then extract the partx1
that you want: