# 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.

edit retag close merge delete

Could 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 ?

( 2016-06-29 23:12:42 +0200 )edit

Sort by ยป oldest newest most voted

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.

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).

more

What 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.

( 2016-06-29 17:31:51 +0200 )edit

Rephrased, 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?

( 2016-06-29 17:35:14 +0200 )edit

When 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.

( 2016-06-29 19:36:01 +0200 )edit

Could 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 ?

( 2016-06-29 23:41:53 +0200 )edit

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 r1 by Sage.

more

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?

( 2016-06-29 17:36:53 +0200 )edit
( 2016-06-30 10:21:34 +0200 )edit