RE: How to get Mathematica to solve for "nonbasic variables"?
- To: mathgroup at smc.vnet.net
- Subject: [mg42375] RE: [mg42359] How to get Mathematica to solve for "nonbasic variables"?
- From: "David Park" <djmp at earthlink.net>
- Date: Thu, 3 Jul 2003 06:10:31 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
cdj,
First, you could solve "by hand".
5x == 6y
#/5/y & /@ %
5 x == 6 y
x/y == 6/5
Or you could solve with the extra variable z and then use z as a
substitution rule in the final solution.
eqns = {5x == 6y, z == x/y};
Solve[eqns, z, x][[1, 1]]
% /. z -> x/y
z -> 6/5
x/y -> 6/5
Still, it would be nice to have a routine that allowed you to solve for
simple expressions. I am putting forward the following candidate, but I am
not at all confident of its general use. Maybe some of the mathematicians in
the group could put forward something better.
SolveForExpressions[exprs__][eqns_, vars_, elims_:{}] :=
Module[
{u = Unique[u],
n = Length[{exprs}],
neweqns, subrules, newvars, extendedeqns, extendedvars},
newvars = Array[u, n];
neweqns = Thread[newvars == {exprs}];
subrules = Thread[newvars -> {exprs}];
extendedeqns = Join[eqns, neweqns];
extendedvars = Join[vars, newvars];
Solve[extendedeqns, extendedvars, elims] /. subrules
]
Then we could at least solve for homogenous coordinates.
eqns = {3x + 4y + 3z == 0, 2x - y + z == 0};
SolveForExpressions[x/z, y/z][eqns, {}]
{{x/z -> -(7/11), y/z -> -(3/11)}}
or some nonlinear equations.
eqns = {x^2 + y^2 == z^2};
sols = SolveForExpressions[x/z, y/z][eqns, {}, {z}]
{{x/z -> -(x/Sqrt[x^2 + y^2]),
y/z -> -(y/Sqrt[x^2 + y^2])},
{x/z -> x/Sqrt[x^2 + y^2], y/z -> y/Sqrt[x^2 + y^2]}}
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
From: cdj [mailto:a_cjones at hotmail.com]
To: mathgroup at smc.vnet.net
Hi all,
Intuitively, I'd like to get Mathematica to compute things of the following
sort:
In: Solve[5x==6y,x/y]
Out: {x/y -> 5/6}
Of course Mathematica won't do this - and several obvious variations on this
theme don't seem to work either (e.g., introducing a new variable z =
x/y, and attempting to solve the system for z).
So what's the easiest way to solve (systems of) equations for
nonatomic variables of this sort?
Thanks for any suggestions,
cdj