ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 26 Aug 2014 20:02:40 +0200Use a symbolic solved variable in another later equationhttps://ask.sagemath.org/question/23933/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.
Tue, 26 Aug 2014 17:35:31 +0200https://ask.sagemath.org/question/23933/use-a-symbolic-solved-variable-in-another-later-equation/Answer by tmonteil for <p>So I just started using sage but I can't find this (or I don't know how to formulate it).</p>
<p>I have an equation that I solved and I want to use that solved variable in a new equation:</p>
<pre><code>a, b, c, d = var('a b c d')
eq1=a+b==d
eq2=solve([eq1],b)
eq3=c/eq2
</code></pre>
<p>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.</p>
https://ask.sagemath.org/question/23933/use-a-symbolic-solved-variable-in-another-later-equation/?answer=23935#post-id-23935As 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)
Tue, 26 Aug 2014 17:42:51 +0200https://ask.sagemath.org/question/23933/use-a-symbolic-solved-variable-in-another-later-equation/?answer=23935#post-id-23935Comment by wzawzdb for <p>As you can see <code>eq2</code> is a list containing a single element:</p>
<pre><code>sage: eq2
[b == -a + d]
</code></pre>
<p>To get it, just type</p>
<pre><code>sage: eq2[0]
b == -a + d
</code></pre>
<p>Now this equality has two sides. You can get its left hand side, and right hand side as folows:</p>
<pre><code>sage: eq2[0].left_hand_side()
b
sage: eq2[0].right_hand_side()
-a + d
</code></pre>
<p>or simply: </p>
<pre><code>sage: eq2[0].lhs()
b
sage: eq2[0].rhs()
-a + d
</code></pre>
<p>So, i guess what you are looking for is:</p>
<pre><code>sage: eq3=c/eq2[0].rhs()
sage: eq3
-c/(a - d)
</code></pre>
https://ask.sagemath.org/question/23933/use-a-symbolic-solved-variable-in-another-later-equation/?comment=23938#post-id-23938Wow 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?Tue, 26 Aug 2014 17:58:00 +0200https://ask.sagemath.org/question/23933/use-a-symbolic-solved-variable-in-another-later-equation/?comment=23938#post-id-23938Comment by tmonteil for <p>As you can see <code>eq2</code> is a list containing a single element:</p>
<pre><code>sage: eq2
[b == -a + d]
</code></pre>
<p>To get it, just type</p>
<pre><code>sage: eq2[0]
b == -a + d
</code></pre>
<p>Now this equality has two sides. You can get its left hand side, and right hand side as folows:</p>
<pre><code>sage: eq2[0].left_hand_side()
b
sage: eq2[0].right_hand_side()
-a + d
</code></pre>
<p>or simply: </p>
<pre><code>sage: eq2[0].lhs()
b
sage: eq2[0].rhs()
-a + d
</code></pre>
<p>So, i guess what you are looking for is:</p>
<pre><code>sage: eq3=c/eq2[0].rhs()
sage: eq3
-c/(a - d)
</code></pre>
https://ask.sagemath.org/question/23933/use-a-symbolic-solved-variable-in-another-later-equation/?comment=23939#post-id-23939I do not understand your problem. What did you type precisely ?Tue, 26 Aug 2014 18:04:57 +0200https://ask.sagemath.org/question/23933/use-a-symbolic-solved-variable-in-another-later-equation/?comment=23939#post-id-23939Comment by wzawzdb for <p>As you can see <code>eq2</code> is a list containing a single element:</p>
<pre><code>sage: eq2
[b == -a + d]
</code></pre>
<p>To get it, just type</p>
<pre><code>sage: eq2[0]
b == -a + d
</code></pre>
<p>Now this equality has two sides. You can get its left hand side, and right hand side as folows:</p>
<pre><code>sage: eq2[0].left_hand_side()
b
sage: eq2[0].right_hand_side()
-a + d
</code></pre>
<p>or simply: </p>
<pre><code>sage: eq2[0].lhs()
b
sage: eq2[0].rhs()
-a + d
</code></pre>
<p>So, i guess what you are looking for is:</p>
<pre><code>sage: eq3=c/eq2[0].rhs()
sage: eq3
-c/(a - d)
</code></pre>
https://ask.sagemath.org/question/23933/use-a-symbolic-solved-variable-in-another-later-equation/?comment=23940#post-id-23940Well 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 errorTue, 26 Aug 2014 18:14:59 +0200https://ask.sagemath.org/question/23933/use-a-symbolic-solved-variable-in-another-later-equation/?comment=23940#post-id-23940Comment by wzawzdb for <p>As you can see <code>eq2</code> is a list containing a single element:</p>
<pre><code>sage: eq2
[b == -a + d]
</code></pre>
<p>To get it, just type</p>
<pre><code>sage: eq2[0]
b == -a + d
</code></pre>
<p>Now this equality has two sides. You can get its left hand side, and right hand side as folows:</p>
<pre><code>sage: eq2[0].left_hand_side()
b
sage: eq2[0].right_hand_side()
-a + d
</code></pre>
<p>or simply: </p>
<pre><code>sage: eq2[0].lhs()
b
sage: eq2[0].rhs()
-a + d
</code></pre>
<p>So, i guess what you are looking for is:</p>
<pre><code>sage: eq3=c/eq2[0].rhs()
sage: eq3
-c/(a - d)
</code></pre>
https://ask.sagemath.org/question/23933/use-a-symbolic-solved-variable-in-another-later-equation/?comment=23943#post-id-23943It 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 1Tue, 26 Aug 2014 20:02:40 +0200https://ask.sagemath.org/question/23933/use-a-symbolic-solved-variable-in-another-later-equation/?comment=23943#post-id-23943Comment by tmonteil for <p>As you can see <code>eq2</code> is a list containing a single element:</p>
<pre><code>sage: eq2
[b == -a + d]
</code></pre>
<p>To get it, just type</p>
<pre><code>sage: eq2[0]
b == -a + d
</code></pre>
<p>Now this equality has two sides. You can get its left hand side, and right hand side as folows:</p>
<pre><code>sage: eq2[0].left_hand_side()
b
sage: eq2[0].right_hand_side()
-a + d
</code></pre>
<p>or simply: </p>
<pre><code>sage: eq2[0].lhs()
b
sage: eq2[0].rhs()
-a + d
</code></pre>
<p>So, i guess what you are looking for is:</p>
<pre><code>sage: eq3=c/eq2[0].rhs()
sage: eq3
-c/(a - d)
</code></pre>
https://ask.sagemath.org/question/23933/use-a-symbolic-solved-variable-in-another-later-equation/?comment=23941#post-id-23941I 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.Tue, 26 Aug 2014 18:24:49 +0200https://ask.sagemath.org/question/23933/use-a-symbolic-solved-variable-in-another-later-equation/?comment=23941#post-id-23941