Re: Min[], Max[]
- To: mathgroup at smc.vnet.net
- Subject: [mg48344] Re: Min[], Max[]
- From: Jim Jennings <jim.jennings at beg.utexas.edu>
- Date: Tue, 25 May 2004 07:17:08 -0400 (EDT)
- Organization: The University of Texas at Austin
- References: <c8rutb$8nl$1@smc.vnet.net>
- Reply-to: jim.jennings at beg.utexas.edu
- Sender: owner-wri-mathgroup at wolfram.com
In article <c8rutb$8nl$1 at smc.vnet.net>, Frank Brand <fank.brand at t-online.de> wrote: > Dear newsgroup members, > > can anyone explain me what´s the sense in the definition of > > Min[{}]= Infinity and Max[{}]= -Infinity > I don't know for sure but I have a guess: When I have a need to find the min (or max) of an array in C or Fortran, I usually do it by looping through the array and comparing each value to the previous min (or max) value. Whenever I find a number smaller (or larger) than the previous min (or max), I replace it with the new one. When the program is done looping through the array the min (or max) is found. It is a simple method, but it needs a starting value. What value for min (or max) do you use to initialize before you enter the loop? It needs to be larger (or smaller) than the min or (max), or you won't find the min (or max) of the list. How do you initialize with a value larger (or smaller) than the min or (max) of the array if you don't know the min (or max) yet? One way is to use a value larger (or smaller) than *any* value in the list (another way is to use any value from the list). In C or Fortran code an easy way to do that is to use the largest (or smallest) number the machine can recognize for your particular variable type. For the Mathematica programmers, it makes sense that that would be Infinity (or -Infinity). If you ask this method to find the min (or max) of an empty list it just returns the initial value. Anyone have a better explanation? -- Jim Jennings, Research Scientist, Bureau of Economic Geology John A. and Katherine G. Jackson School of Geosciences The University of Texas at Austin http://www.beg.utexas.edu/staffinfo/jennings01.htm