Ask Your Question
0

How do I coerce solve to solve for each of the variables in the system?

asked 2016-06-29 16:25:05 +0200

nacitar gravatar image

updated 2016-06-29 17:51:56 +0200

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 flag offensive close merge delete

Comments

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 ?

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

2 Answers

Sort by ยป oldest newest most voted
0

answered 2016-06-29 16:44:33 +0200

tmonteil gravatar image

updated 2016-06-29 16:45:00 +0200

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

edit flag offensive delete link more

Comments

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.

nacitar gravatar imagenacitar ( 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?

nacitar gravatar imagenacitar ( 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.

calc314 gravatar imagecalc314 ( 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 ?

tmonteil gravatar imagetmonteil ( 2016-06-29 23:41:53 +0200 )edit
1

answered 2016-06-29 16:42:32 +0200

eric_g gravatar image

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.

edit flag offensive delete link more

Comments

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?

nacitar gravatar imagenacitar ( 2016-06-29 17:36:53 +0200 )edit
ndomes gravatar imagendomes ( 2016-06-30 10:21:34 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-06-29 16:25:05 +0200

Seen: 489 times

Last updated: Jun 29 '16