# Use a symbolic solved variable in another later equation

So I just started using sage but I can't find this (or I don't know how to formulate it).

I have an equation that I solved and I want to use that solved variable in a new equation:

a, b, c, d = var('a b c d')
eq1=a+b==d
eq2=solve([eq1],b)
eq3=c/eq2


but this doesn't work and of course I can do c/b but then it just gives me c/b and I want c/(d-a) as an answer.

edit retag close merge delete

Sort by ยป oldest newest most voted

As you can see eq2 is a list containing a single element:

sage: eq2
[b == -a + d]


To get it, just type

sage: eq2[0]
b == -a + d


Now this equality has two sides. You can get its left hand side, and right hand side as folows:

sage: eq2[0].left_hand_side()
b
sage: eq2[0].right_hand_side()
-a + d


or simply:

sage: eq2[0].lhs()
b
sage: eq2[0].rhs()
-a + d


So, i guess what you are looking for is:

sage: eq3=c/eq2[0].rhs()
sage: eq3
-c/(a - d)

more

Wow that's fast! thanks. But eq2[0].rhs() works but as soon as i put it into the equation it gives me an (syntax) error? And i accidentally searched in google in the virtual box, how do i go back to my equations?

( 2014-08-26 17:58:00 +0200 )edit

I do not understand your problem. What did you type precisely ?

( 2014-08-26 18:04:57 +0200 )edit

Well first i tried it and then i clicked search with google and now I see a google page and can't get back to my equations... for the equations I typed eq2[0].rhs() and it gave me the right answer. i then copied and pasted it into the other equation and it then gave me a syntax error

( 2014-08-26 18:14:59 +0200 )edit

I do not know what to advise, perhaps start again from the beginning... There shoud not be any syntax error unless you added some bad character. If there is a syntax error, you can read the traceback by clicking on the left of the error message.

( 2014-08-26 18:24:49 +0200 )edit

It works now probably forgot a bracket or something, thanks! can you also help me now with a substitution? I have a formula let say eq1=a*z==(b+c)k eq2=d==a*z+f eq3=eq2.subs(eq1)/g (doesnt work with the multiplication?) so it does some kind of operation on equation 2 but I want to replace the a in equation 2 for equation 1

( 2014-08-26 20:02:40 +0200 )edit