Re: roots
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg1572] Re: roots
- From: bob Hanlon <hanlon at pafosu2.hq.af.mil>
- Date: Sat, 1 Jul 1995 02:18:04 -0400
An approach: soln1 = { { x -> -27 p^3/(16 r^2 w) }, { x -> 27 p^3/(16 r^2 w) } }; (* only one is positive *) soln2 = { { x -> -27 p^3/(16 r^2 w) }, { x -> 15 }, { x -> 27 p^3/(16 r^2 w) } }; (* two are positive *) selectMax[soln__List, subValue_:1] := Module[ { var = soln[[1, 1, 1]], posReplace, maxValue }, posReplace = (# -> subValue &) /@ Variables[ var /. soln ]; (* substitutes subValue for all variables *) maxValue = Max[ var /. soln /. posReplace ]; Select[ soln, (var /. # /. posReplace) == maxValue & ] ] { selectMax[soln1], selectMax[soln2], selectMax[soln2 /. p -> 4] } 3 27 p 108 {{{x -> -------}}, {{x -> 15}}, {{x -> ----}}} 2 2 16 r w r w Although your question concerned finding the maximum (largest) value, this approach is highly dependent on the form of the solutions being sufficiently similar so that the relative values are not dependent on the specific values of the variables. For your example, this is the case; actually what is desired for this case is the positive value. A test for positive rather than maximum is far more robust since it only depends on the variables being positive. selectPos[soln__List, subValue_:1] := Module[ { var = soln[[1, 1, 1]], posReplace }, posReplace = (# -> subValue &) /@ Variables[ var /. soln ]; (* substitutes subValue for all variables *) Select[ soln, Positive[ var /. # /. posReplace ] & ] ] { selectPos[soln1], selectPos[soln2] } 3 3 27 p 27 p {{{x -> -------}}, {{x -> 15}, {x -> -------}}} 2 2 16 r w 16 r w > From: jlw12 at cornell.edu (jason weisman) > Newsgroups: comp.soft-sys.math.mathematica > Subject: roots > Date: 24 Jun 1995 04:22:10 GMT > > I would like to be able to choose the largest "positive" root in expressions > like the one below. All the variables (p2, r, and w) are positive, real > numbers. Can anyone give me a method to do that? Thanks. > > 3 3 > -27 p2 p2 > Out[31]= {{x20 -> -------}, {x20 -> -------}} > 2 2 > 16 r w 16 r w