ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 04 Dec 2013 08:27:09 -0600How to make solve to use certain variables on the right sidehttp://ask.sagemath.org/question/8247/how-to-make-solve-to-use-certain-variables-on-the-right-side/if I have
I1, IR1, IR2, U1, R1, R2 = var('I1 IR1 IR2 U1 R1 R2')
equations = [
I1 == IR1 + IR2,
IR1 == U1/R1,
IR2 == U1/R2
]
how can I make solve to return
I == (R1 + R2)*U1/(R1*R2)
?
solve(equations, I)
now returns just an empty list
or similait problem is with
I1, IC1, IC2, U1d, U2d, C1, C2 = var('I1, IC1, IC2, U1d, U2d, C1, C2')
equations = [
I1 == IC1 + IC2,
IC1 == C1*U1d,
IC2 == C2*U1d
]
and desired result is
I1 == (C1 + C2)*IC2/C2
Fri, 29 Jul 2011 12:56:54 -0500http://ask.sagemath.org/question/8247/how-to-make-solve-to-use-certain-variables-on-the-right-side/Answer by benjaminfjones for <p>if I have</p>
<pre><code>I1, IR1, IR2, U1, R1, R2 = var('I1 IR1 IR2 U1 R1 R2')
equations = [
I1 == IR1 + IR2,
IR1 == U1/R1,
IR2 == U1/R2
]
</code></pre>
<p>how can I make solve to return</p>
<pre><code>I == (R1 + R2)*U1/(R1*R2)
</code></pre>
<p>?</p>
<pre><code>solve(equations, I)
</code></pre>
<p>now returns just an empty list</p>
<p>or similait problem is with</p>
<pre><code>I1, IC1, IC2, U1d, U2d, C1, C2 = var('I1, IC1, IC2, U1d, U2d, C1, C2')
equations = [
I1 == IC1 + IC2,
IC1 == C1*U1d,
IC2 == C2*U1d
]
</code></pre>
<p>and desired result is</p>
<pre><code>I1 == (C1 + C2)*IC2/C2
</code></pre>
http://ask.sagemath.org/question/8247/how-to-make-solve-to-use-certain-variables-on-the-right-side/?answer=12548#post-id-12548I don't know what `I` is in your code, perhaps you meant `I1`. It looks like to me that you have one equation involving `I1` and you want to substitute the values of `IR1` and `IR2` from the second two equations into it. If that's really all you want, then calling `solve` is overkill. Try this:
sage: eqn = I1 == IR1 + IR2
sage: eqn = eqn.subs(IR1 == U1/R1)
sage: eqn = eqn.subs(IR2 == U1/R2)
sage: eqn
I1 == U1/R1 + U1/R2
sage: eqn.rhs()
U1/R1 + U1/R2
sage: eqn.rhs().factor()
(R1 + R2)*U1/(R1*R2)
Mon, 01 Aug 2011 10:32:23 -0500http://ask.sagemath.org/question/8247/how-to-make-solve-to-use-certain-variables-on-the-right-side/?answer=12548#post-id-12548Comment by Ondra for <p>I don't know what <code>I</code> is in your code, perhaps you meant <code>I1</code>. It looks like to me that you have one equation involving <code>I1</code> and you want to substitute the values of <code>IR1</code> and <code>IR2</code> from the second two equations into it. If that's really all you want, then calling <code>solve</code> is overkill. Try this:</p>
<pre><code>sage: eqn = I1 == IR1 + IR2
sage: eqn = eqn.subs(IR1 == U1/R1)
sage: eqn = eqn.subs(IR2 == U1/R2)
sage: eqn
I1 == U1/R1 + U1/R2
sage: eqn.rhs()
U1/R1 + U1/R2
sage: eqn.rhs().factor()
(R1 + R2)*U1/(R1*R2)
</code></pre>
http://ask.sagemath.org/question/8247/how-to-make-solve-to-use-certain-variables-on-the-right-side/?comment=21252#post-id-21252yes! factor() is what I was looking for. but this returns "(R1 + R2)*U1/(R1*R2)". can I make it somehow to return "I1 == (R1 + R2)*U1/(R1*R2)"? from the documentation, it seems that factor only is method of expressions, not equations.Fri, 16 Sep 2011 08:05:06 -0500http://ask.sagemath.org/question/8247/how-to-make-solve-to-use-certain-variables-on-the-right-side/?comment=21252#post-id-21252Answer by Hazon Da'kir for <p>if I have</p>
<pre><code>I1, IR1, IR2, U1, R1, R2 = var('I1 IR1 IR2 U1 R1 R2')
equations = [
I1 == IR1 + IR2,
IR1 == U1/R1,
IR2 == U1/R2
]
</code></pre>
<p>how can I make solve to return</p>
<pre><code>I == (R1 + R2)*U1/(R1*R2)
</code></pre>
<p>?</p>
<pre><code>solve(equations, I)
</code></pre>
<p>now returns just an empty list</p>
<p>or similait problem is with</p>
<pre><code>I1, IC1, IC2, U1d, U2d, C1, C2 = var('I1, IC1, IC2, U1d, U2d, C1, C2')
equations = [
I1 == IC1 + IC2,
IC1 == C1*U1d,
IC2 == C2*U1d
]
</code></pre>
<p>and desired result is</p>
<pre><code>I1 == (C1 + C2)*IC2/C2
</code></pre>
http://ask.sagemath.org/question/8247/how-to-make-solve-to-use-certain-variables-on-the-right-side/?answer=15759#post-id-15759Did I do this right, I1=(R1+R2)U2/(R1R2) ok R= reality, U= universe
I1= (31+32)12/(3132), I1=(3+6)12/(36), I1=92/18, I1=18/18, I1=1, I=1. I might just be a total numbskull I don't even know if this has anything to do with your guy's equations sorry if I was way off.Wed, 04 Dec 2013 08:27:09 -0600http://ask.sagemath.org/question/8247/how-to-make-solve-to-use-certain-variables-on-the-right-side/?answer=15759#post-id-15759