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.Thu, 30 Jun 2016 10:21:34 +0200How do I coerce solve to solve for each of the variables in the system?https://ask.sagemath.org/question/33961/how-do-i-coerce-solve-to-solve-for-each-of-the-variables-in-the-system/EDITED QUESTION FOR CLARITY
X, Y = var('x y')
eq = (Y == 90 + X)
# Properly prints [y == x + 90]
print(solve(eq,[Y]))
# Properly prints [x == y - 90]
print(solve(eq,[X]))
# Rather than printing what I expected: [x == y - 90, y == x + 90]
# It prints: [x == r1 - 90, y == r1]
print(solve(eq,[X,Y]))
How can I get the result I expect out of this? In my actual usage, I could have 10+ unknowns, each of which I want the equations rearranged(solved) for those variables, that way I can fetch an equation for each one as needed, already solved for with just that one variable on the left hand side. If solve doesn't do this, what will? It seems like I should be able to do this with one invocation.. but perhaps I'm mistaken.Wed, 29 Jun 2016 16:25:05 +0200https://ask.sagemath.org/question/33961/how-do-i-coerce-solve-to-solve-for-each-of-the-variables-in-the-system/Comment by tmonteil for <p>EDITED QUESTION FOR CLARITY</p>
<pre><code>X, Y = var('x y')
eq = (Y == 90 + X)
# Properly prints [y == x + 90]
print(solve(eq,[Y]))
# Properly prints [x == y - 90]
print(solve(eq,[X]))
# Rather than printing what I expected: [x == y - 90, y == x + 90]
# It prints: [x == r1 - 90, y == r1]
print(solve(eq,[X,Y]))
</code></pre>
<p>How can I get the result I expect out of this? In my actual usage, I could have 10+ unknowns, each of which I want the equations rearranged(solved) for those variables, that way I can fetch an equation for each one as needed, already solved for with just that one variable on the left hand side. If solve doesn't do this, what will? It seems like I should be able to do this with one invocation.. but perhaps I'm mistaken.</p>
https://ask.sagemath.org/question/33961/how-do-i-coerce-solve-to-solve-for-each-of-the-variables-in-the-system/?comment=33969#post-id-33969Could you please provide a concrete example with 10+ unknows so that we can see how do your equations look like ? For example, are there all affine ?Wed, 29 Jun 2016 23:12:42 +0200https://ask.sagemath.org/question/33961/how-do-i-coerce-solve-to-solve-for-each-of-the-variables-in-the-system/?comment=33969#post-id-33969Answer by eric_g for <p>EDITED QUESTION FOR CLARITY</p>
<pre><code>X, Y = var('x y')
eq = (Y == 90 + X)
# Properly prints [y == x + 90]
print(solve(eq,[Y]))
# Properly prints [x == y - 90]
print(solve(eq,[X]))
# Rather than printing what I expected: [x == y - 90, y == x + 90]
# It prints: [x == r1 - 90, y == r1]
print(solve(eq,[X,Y]))
</code></pre>
<p>How can I get the result I expect out of this? In my actual usage, I could have 10+ unknowns, each of which I want the equations rearranged(solved) for those variables, that way I can fetch an equation for each one as needed, already solved for with just that one variable on the left hand side. If solve doesn't do this, what will? It seems like I should be able to do this with one invocation.. but perhaps I'm mistaken.</p>
https://ask.sagemath.org/question/33961/how-do-i-coerce-solve-to-solve-for-each-of-the-variables-in-the-system/?answer=33962#post-id-33962The answer you get is not meaningless: if you consider y == 90 + x as an equation for the unknown (x,y), then it is underdeterminate and hence has an infinite number of solutions. The solution family is parametrized by a single parameter, which is denoted by `r1` by Sage.Wed, 29 Jun 2016 16:42:32 +0200https://ask.sagemath.org/question/33961/how-do-i-coerce-solve-to-solve-for-each-of-the-variables-in-the-system/?answer=33962#post-id-33962Comment by nacitar for <p>The answer you get is not meaningless: if you consider y == 90 + x as an equation for the unknown (x,y), then it is underdeterminate and hence has an infinite number of solutions. The solution family is parametrized by a single parameter, which is denoted by <code>r1</code> by Sage.</p>
https://ask.sagemath.org/question/33961/how-do-i-coerce-solve-to-solve-for-each-of-the-variables-in-the-system/?comment=33966#post-id-33966I'm basically trying to use this for basic algebra, getting a single variable on the LHS of the equation, for each of the variables included in my system of equations. If not using solve in this way, how could I do it?Wed, 29 Jun 2016 17:36:53 +0200https://ask.sagemath.org/question/33961/how-do-i-coerce-solve-to-solve-for-each-of-the-variables-in-the-system/?comment=33966#post-id-33966Comment by ndomes for <p>The answer you get is not meaningless: if you consider y == 90 + x as an equation for the unknown (x,y), then it is underdeterminate and hence has an infinite number of solutions. The solution family is parametrized by a single parameter, which is denoted by <code>r1</code> by Sage.</p>
https://ask.sagemath.org/question/33961/how-do-i-coerce-solve-to-solve-for-each-of-the-variables-in-the-system/?comment=33972#post-id-33972An example see: [sagecell.sagemath.org/?q=ndhqcd](http://sagecell.sagemath.org/?q=ndhqcd)Thu, 30 Jun 2016 10:21:34 +0200https://ask.sagemath.org/question/33961/how-do-i-coerce-solve-to-solve-for-each-of-the-variables-in-the-system/?comment=33972#post-id-33972Answer by tmonteil for <p>EDITED QUESTION FOR CLARITY</p>
<pre><code>X, Y = var('x y')
eq = (Y == 90 + X)
# Properly prints [y == x + 90]
print(solve(eq,[Y]))
# Properly prints [x == y - 90]
print(solve(eq,[X]))
# Rather than printing what I expected: [x == y - 90, y == x + 90]
# It prints: [x == r1 - 90, y == r1]
print(solve(eq,[X,Y]))
</code></pre>
<p>How can I get the result I expect out of this? In my actual usage, I could have 10+ unknowns, each of which I want the equations rearranged(solved) for those variables, that way I can fetch an equation for each one as needed, already solved for with just that one variable on the left hand side. If solve doesn't do this, what will? It seems like I should be able to do this with one invocation.. but perhaps I'm mistaken.</p>
https://ask.sagemath.org/question/33961/how-do-i-coerce-solve-to-solve-for-each-of-the-variables-in-the-system/?answer=33963#post-id-33963In the first case, x is fixed and y is the unknown. In the second case, y is fixed and x is the unknown. In the third case, both x and y are unknown, and the set of solutions is of dimension 1, hence the need for a parameter r1.
The fact that the parameter r1 is in direct bijection with y is only a consequence of the fact that your equation is very simple (affine).
Wed, 29 Jun 2016 16:44:33 +0200https://ask.sagemath.org/question/33961/how-do-i-coerce-solve-to-solve-for-each-of-the-variables-in-the-system/?answer=33963#post-id-33963Comment by nacitar for <p>In the first case, x is fixed and y is the unknown. In the second case, y is fixed and x is the unknown. In the third case, both x and y are unknown, and the set of solutions is of dimension 1, hence the need for a parameter r1.</p>
<p>The fact that the parameter r1 is in direct bijection with y is only a consequence of the fact that your equation is very simple (affine).</p>
https://ask.sagemath.org/question/33961/how-do-i-coerce-solve-to-solve-for-each-of-the-variables-in-the-system/?comment=33964#post-id-33964What I'm after here, though, is to just have the equation rearranged (solved) so I can get VAR = EXPRESSION for all variables. In a system where there's 6 variables in play, all of which are dependent on other variables (which are not defined), I'd want solve to give me equations solved for each of those values. If not by specifying a list of all of the variables, how else would I ask for this?
I could invoke solve N times, once for each of the N variables I need the equations for, but that's quite slow. It seems like asking for them all at once should be the same thing as asking for each one individually, but in one invocation... It really seems unintuitive to me that asking for [X,Y] is not the same thing as asking for X and Y separately and combining the results.Wed, 29 Jun 2016 17:31:51 +0200https://ask.sagemath.org/question/33961/how-do-i-coerce-solve-to-solve-for-each-of-the-variables-in-the-system/?comment=33964#post-id-33964Comment by nacitar for <p>In the first case, x is fixed and y is the unknown. In the second case, y is fixed and x is the unknown. In the third case, both x and y are unknown, and the set of solutions is of dimension 1, hence the need for a parameter r1.</p>
<p>The fact that the parameter r1 is in direct bijection with y is only a consequence of the fact that your equation is very simple (affine).</p>
https://ask.sagemath.org/question/33961/how-do-i-coerce-solve-to-solve-for-each-of-the-variables-in-the-system/?comment=33965#post-id-33965Rephrased, I'm basically trying to use this for basic algebra, getting a single variable on the LHS of the equation, for each of the variables included in my system of equations. If not using solve in this way, how could I do it?Wed, 29 Jun 2016 17:35:14 +0200https://ask.sagemath.org/question/33961/how-do-i-coerce-solve-to-solve-for-each-of-the-variables-in-the-system/?comment=33965#post-id-33965Comment by calc314 for <p>In the first case, x is fixed and y is the unknown. In the second case, y is fixed and x is the unknown. In the third case, both x and y are unknown, and the set of solutions is of dimension 1, hence the need for a parameter r1.</p>
<p>The fact that the parameter r1 is in direct bijection with y is only a consequence of the fact that your equation is very simple (affine).</p>
https://ask.sagemath.org/question/33961/how-do-i-coerce-solve-to-solve-for-each-of-the-variables-in-the-system/?comment=33967#post-id-33967When you ask for `solve` to solve for [x,y], you are requesting that it solve the system for x and y simultaneously, which is usually what is desired with a system. What you are requesting is to solve for x and solve for y independently. So, Sage requires that you ask for each separately. You could write a function that does the iterations for you to reduce the difficulty of re-entering the code.Wed, 29 Jun 2016 19:36:01 +0200https://ask.sagemath.org/question/33961/how-do-i-coerce-solve-to-solve-for-each-of-the-variables-in-the-system/?comment=33967#post-id-33967Comment by tmonteil for <p>In the first case, x is fixed and y is the unknown. In the second case, y is fixed and x is the unknown. In the third case, both x and y are unknown, and the set of solutions is of dimension 1, hence the need for a parameter r1.</p>
<p>The fact that the parameter r1 is in direct bijection with y is only a consequence of the fact that your equation is very simple (affine).</p>
https://ask.sagemath.org/question/33961/how-do-i-coerce-solve-to-solve-for-each-of-the-variables-in-the-system/?comment=33970#post-id-33970Could you please provide a concrete example with 10+ unknows so that we can see how do your equations look like ? For example, are there all affine ?Wed, 29 Jun 2016 23:41:53 +0200https://ask.sagemath.org/question/33961/how-do-i-coerce-solve-to-solve-for-each-of-the-variables-in-the-system/?comment=33970#post-id-33970