# 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.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
{"ft_lang_label":"__label__en","ft_lang_prob":0.9181838,"math_prob":0.99920076,"size":634,"snap":"2022-27-2022-33","text_gpt3_token_len":175,"char_repetition_ratio":0.09047619,"word_repetition_ratio":0.0,"special_character_ratio":0.28548896,"punctuation_ratio":0.1459854,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99983764,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-08-16T03:42:37Z\",\"WARC-Record-ID\":\"<urn:uuid:bbe38095-f873-42fb-aecf-47ad05fcc5f4>\",\"Content-Length\":\"59770\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:3310e6ba-bc5b-4638-bb37-e530a65de8be>\",\"WARC-Concurrent-To\":\"<urn:uuid:73520983-c0f4-4ddc-8ef0-155b962c3507>\",\"WARC-IP-Address\":\"194.254.163.53\",\"WARC-Target-URI\":\"https://ask.sagemath.org/question/9749/solve-an-equation-in-terms-of-an-expression/\",\"WARC-Payload-Digest\":\"sha1:O2GSMQIMGSOQR4AQEVMKHOJDLPTDRA54\",\"WARC-Block-Digest\":\"sha1:443GSURHAY5QH5RLBS3I6Q3PF4FJRIO5\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-33/CC-MAIN-2022-33_segments_1659882572220.19_warc_CC-MAIN-20220816030218-20220816060218-00369.warc.gz\"}"}