Re: Evaluating Min[2^(1/2),3^(1/2)]
- To: mathgroup at yoda.physics.unc.edu
- Subject: Re: Evaluating Min[2^(1/2),3^(1/2)]
- From: TODD GAYLEY <TGAYLEY at ccit.arizona.edu>
- Date: Mon, 10 Aug 1992 01:17 MST
Roger B. Kirchner (kirchner at cs.umn.edu) asks: > I would like a way to explicitly find the minimum of a list of > exact numbers. Is there a way to get Min[2^(1/2),3^(1/2)] to > evaluate to 2^(1/2)? > I also want to be able to select an expression in a list which > is smallest when any symbols are given numerical values. I > could do this if I knew how to find the subscript of a member > of a list which is smallest. The best way to get Min to work on such expressions is to force them to be evaluated numerically: In[] := Min[ N[2^(1/2)], N[3^(1/2)] ] Out[] = 1.41421 But of course you want 2^(1/2), not 1.4121. You need to evaluate the list numerically, find the Min, find its position, and then get that element from the original list. An easy method to get the position of the smallest member of a list is to just use Position[list,Min[list]]. Obviously, finding the min and then going back into the list to find elements that match it is not very efficient, but this method works quite quickly unless the list is very large. Putting it together, we can define NMin: NMin[items__] := Module[ {nlist = N /@ {items}}, {items}[[ First at First@Position[nlist,Min[nlist]] ]] ] (We need the two Firsts to strip off unwanted braces returned by Position.) In[] := NMin[2^(1/2),3^(1/2)] Out[] = Sqrt[2] Note that in its present form, NMin is designed to take a sequence of values (as in your example), not a list. --Todd Gayley --University of Arizona