# solve an equation in terms of an expression?

Hi,

Not entirely sure if I worded the subject line of this question right, Essentially what I am trying to do is rearrange an equation based on what I want on the left hand side of it, for example:

I have defined my variables:

var('v_o, v_i, delta, T, v_d, v_c')


Entered my equation:

eqn1= v_i * delta * T == v_o + v_d + v_c - v_i * (1-delta) * T


eqn2 = eqn1.substitute(v_c=v_i)


and now, with minimum possible effort I would like sage to put it in the form of:

delta/(1-delta)=...


Many thanks to anyone who's even read this far down, Any help would be much appreciated

edit retag close merge delete

Sort by » oldest newest most voted

You could try solving for delta and then just compute delta/(1-delta). However, in the equation eqn1 you've given delta cancels out on both sides so it isn't possible to solve for it. Here's a simplified example:

sage: a,b,c,d = var('a,b,c,d')
sage: eqn1= a * d == b - a * (1-d)
sage: eqn1
a*d == (d - 1)*a + b
sage: solve(eqn1, d)
[]


Which means that any value of d is a solution. So maybe you've got a typo in your equation. If, for example, you start with the $a * d == b + a * (1-d)$ --notice that I changed one of the signs on the right hand side-- and you want to derive an expresion for $d/(1-d)$ you could do:

sage: a,b,c,d = var('a,b,c,d')
sage: eqn1= a * d == b + a * (1-d)
sage: S = solve(eqn1, d); S
[d == 1/2*(a + b)/a]
sage: soln_d = S[0].rhs(); soln_d
1/2*(a + b)/a
sage: soln_d / (1 - soln_d)
-(a + b)/(((a + b)/a - 2)*a)

more

Let Sage solve a system of equations:

sage: a,b,c,d,z = var('a,b,c,d,z')
sage: eqn1= a * d == b + a * (1-d)
sage: eqn2 = z == d / (1 - d)
sage: S = solve([eqn1,eqn2], d,z);  S


[ [d == 1/2*(a + b)/a, z == (a + b)/(a - b)] ]

more