| 1 | initial version |
You could solve for a, b, c, d and then ignore c and d.
sage: a, b, c, d = var('a b c d')
sage: solns = solve([a+b-1,a-b,c+d],[a,b,c,d]); solns
[[a == (1/2), b == (1/2), c == -r1, d == r1]]
sage: [s[:2] for s in solns]
[[a == (1/2), b == (1/2)]]
Or you can tweak solve to only use the equations which involve the variables
that you want to solve for.
sage: def smart_solve(eqns, vars):
....: return solve([eqn for eqn in eqns if
....: any(v in eqn.variables() for v in vars)], vars)
....:
sage: smart_solve([a+b-1,a-b,c+d],[a,b])
[[a == (1/2), b == (1/2)]]
I don't know what would be the pros and cons of having Sage's solve behave
in this way (either by default or as an option).
| 2 | No.2 Revision |
You could solve for a, b, c, d and then ignore c and d.
sage: a, b, c, d = var('a b c d')
sage: solns = solve([a+b-1,a-b,c+d],[a,b,c,d]); solve([a + b - 1, a - b, c + d], [a, b, c, d]); solns
[[a == (1/2), b == (1/2), c == -r1, d == r1]]
sage: [s[:2] for s in solns]
[[a == (1/2), b == (1/2)]]
Or you can tweak solve to only use the equations which involve the variables
that you want to solve for.
sage: def smart_solve(eqns, vars):
....: return solve([eqn for eqn in eqns if
....: any(v in eqn.variables() for v in vars)], vars)
....:
sage: smart_solve([a+b-1,a-b,c+d],[a,b])
smart_solve([a + b - 1, a - b, c + d], [a, b])
[[a == (1/2), b == (1/2)]]
I don't know what would be the pros and cons of having Sage's solve behave
in this way (either by default or as an option).
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.