Difference between revisions of "Functions Min and Max"

m
Line 6: Line 6:
 
= Functions Min and Max =
 
= Functions Min and Max =
  
  Min( X, I )
+
  Min(X, I)
  Max( X, I )
+
  Max(X, I)
  
These return the smallest (Min) or largest (Max) values along an indicated index or indexes.  
+
Returns the smallest (Min) or largest (Max) value in array X over index I.
 +
You can use them to find the smallest or largest value over an explicit list of values enclosed in square brackets, in which case you omit the index:
 +
  Max([a, b, c])
  
To find the larger of separate values, use:
+
This form evaluates a, b, and c, and finds the largest value among them.  For example:
  Max( [a,b,c] )
+
  Max([Sin(30), Tan(30), Cos(30)]) --> 0.8660254
  
This form evaluates a, b, and c, and finds the largest value among them.  For example:
+
Although index I is optional, we strongly recommend you include it even if X currently only has one index. You might expand the model so that X gets another index, J: Then Min(X) would be ambiguous. Analytica couldn't tell whether you meant Min(X, I) or Min(X, J), and might not interpret it the way you want.  
Max( [ [[Sin]](30), [[Tan]](30), [[Cos]](30)] ) --> 0.8660254
 
  
The index parameter is optional, but it is highly recommended that you always specify the index except in the list-usage just mentioned, or in the case where you can guarantee that X will always be one-dimensional (such as when X is itself an index). In most cases, even if your array is 1-D today, it is better to specify the index explicitly so that the expression can correctly array abstract if new dimensions are introduced into your model in the future.
+
If X contains text values, it returns the first (Min) or last (Max) value in alphabetic order. If X contains mixed text and numbers, it treats text before or "smaller than" numbers. Thus,
 +
Min(['A', 'B', 2]) &rarr 'A'
 +
  Max(['A', 'B', 2]) &rarr  2
 +
It orders text as case sensitive unless you specify otherwise with the optional CaseSensitive parameter (see below).
  
 
== Optional Parameters ==
 
== Optional Parameters ==
Line 23: Line 27:
 
=== Multiple Indexes ===
 
=== Multiple Indexes ===
  
  Min( X, I, J, K, ... )
+
  Min(X, I, J, K, ...)
  Min( X, I, J, K, ... )
+
  Min(X, I, J, K, ...)
  
You can list more than one index, e.g., <code>Max(X,I,J)</code>, which is equivalent to <code>Max(Max(X,I),J)</code>. The multi-index variation allows you to find the maximum or minimum within an N-Dimensional slice of ''X''.
+
You can specify more than one index, e.g., <code>Max(X, I, J)</code> is equivalent to <code>Max(Max(X, I), J)</code>. This finds the maximum or minimum over all the specified indexes of ''X''.
  
 
=== Non-Numerics ===
 
=== Non-Numerics ===
  
  Min( X, I'', IgnoreNonNumerics, IgnoreNaN'' )
+
  Min(X, I'', IgnoreNonNumerics, IgnoreNaN'')
  Max( X, I'', IgnoreNonNumerics, IgnoreNaN'' )
+
  Max(X, I'', IgnoreNonNumerics, IgnoreNaN'')
  
These optional boolean parameters require a named-parameter syntax.  Sometimes you want to take the maximum of only the numeric values that appear, ignoring textual values and other non-numeric values. (note: [[Null]] values are always ignored, even when this parameter is not specified)  To do this, supply True for the «IgnoreNonNumerics» parameter, e.g.:
+
If ''IgnoreNonNumerics'' is set to true (1), it ignores non-numeric values.
 +
If ''IgnoreNAN'' is set to true (1), it ignores NAN values.
 +
It always ignores [[NULL]] no matter what the parameter values.
 +
These optional Boolean parameters require a named-parameter syntax.  
  
 
:{| border="1"
 
:{| border="1"
Line 42: Line 49:
 
|}
 
|}
  
:Min( A, I, IgnoreNonNumerics:true ) &rarr 3
+
:Min(A, I, IgnoreNonNumerics: True) &rarr 3
:Max( A, I, IgnoreNonNumerics:true ) &rarr 56
+
:Max(A, I, IgnoreNonNumerics: True) &rarr 56
  
A [[NaN]] value occurs when an arithmetic operation is indeterminate, such as the result of a divide by zero.  Since these are would-be numeric values, but just indeterminate (i.e., we have no way of knowing the real value), the result of a Min or Max on NaN is also indeterminate.  These normally propagate so that you don't get misleading results downstream, but if you also want to ignore NaN values, then include «IgnoreNaN» set to true.
+
A [[NaN]] value occurs when an arithmetic operation is indeterminate, such as the result of a divide by zero.  These are would-be numeric values, but just indeterminate, so the result of a Min or Max on NaN is also NaN.  These normally propagate so that you don't get misleading results downstream, but if you also want to ignore NaN values, then include «IgnoreNaN» set to true.
 
   
 
   
 
=== Case Insensitivity ===
 
=== Case Insensitivity ===
Line 51: Line 58:
 
Comparison of text values by Min and Max is done in a case-sensitive fashion by default.  You can specify the optional «caseInsensitive» parameter as true to do the comparison in a case-insensitive manner, e.g.:
 
Comparison of text values by Min and Max is done in a case-sensitive fashion by default.  You can specify the optional «caseInsensitive» parameter as true to do the comparison in a case-insensitive manner, e.g.:
  
:Min( ['DeBois', 'Debbie', 'Debutante' ] ) &rarr; 'DeBois'
+
:Min(['DeBois', 'Debbie', 'Debutante' ]) &rarr; 'DeBois'
:Min( ['DeBois', 'Debbie', 'Debutante' ], CaseInsensitive:true ) &rarr; 'Debbie'
+
:Min(['DeBois', 'Debbie', 'Debutante' ], CaseInsensitive: True) &rarr; 'Debbie'
  
 
= Functions CondMin and CondMax =
 
= Functions CondMin and CondMax =

Revision as of 18:29, 18 May 2015


Functions Min and Max

Min(X, I)
Max(X, I)

Returns the smallest (Min) or largest (Max) value in array X over index I. You can use them to find the smallest or largest value over an explicit list of values enclosed in square brackets, in which case you omit the index:

Max([a, b, c])

This form evaluates a, b, and c, and finds the largest value among them. For example:

Max([Sin(30), Tan(30), Cos(30)]) --> 0.8660254

Although index I is optional, we strongly recommend you include it even if X currently only has one index. You might expand the model so that X gets another index, J: Then Min(X) would be ambiguous. Analytica couldn't tell whether you meant Min(X, I) or Min(X, J), and might not interpret it the way you want.

If X contains text values, it returns the first (Min) or last (Max) value in alphabetic order. If X contains mixed text and numbers, it treats text before or "smaller than" numbers. Thus,

Min(['A', 'B', 2]) &rarr 'A'
Max(['A', 'B', 2]) &rarr  2

It orders text as case sensitive unless you specify otherwise with the optional CaseSensitive parameter (see below).

Optional Parameters

Multiple Indexes

Min(X, I, J, K, ...)
Min(X, I, J, K, ...)

You can specify more than one index, e.g., Max(X, I, J) is equivalent to Max(Max(X, I), J). This finds the maximum or minimum over all the specified indexes of X.

Non-Numerics

Min(X, I, IgnoreNonNumerics, IgnoreNaN)
Max(X, I, IgnoreNonNumerics, IgnoreNaN)

If IgnoreNonNumerics is set to true (1), it ignores non-numeric values. If IgnoreNAN is set to true (1), it ignores NAN values. It always ignores NULL no matter what the parameter values. These optional Boolean parameters require a named-parameter syntax.

I → 1 2 3 4 5 6 7
A → 56 "a" 4 "1" 3 «null» 45
Min(A, I, IgnoreNonNumerics: True) &rarr 3
Max(A, I, IgnoreNonNumerics: True) &rarr 56

A NaN value occurs when an arithmetic operation is indeterminate, such as the result of a divide by zero. These are would-be numeric values, but just indeterminate, so the result of a Min or Max on NaN is also NaN. These normally propagate so that you don't get misleading results downstream, but if you also want to ignore NaN values, then include «IgnoreNaN» set to true.

Case Insensitivity

Comparison of text values by Min and Max is done in a case-sensitive fashion by default. You can specify the optional «caseInsensitive» parameter as true to do the comparison in a case-insensitive manner, e.g.:

Min(['DeBois', 'Debbie', 'Debutante' ]) → 'DeBois'
Min(['DeBois', 'Debbie', 'Debutante' ], CaseInsensitive: True) → 'Debbie'

Functions CondMin and CondMax

CondMin(X: Array[I]; cond: Boolean[I];  I: Index)
CondMax(X: Array[I]; cond: Boolean[I];  I: Index)

Conditional Min and Max. These return the smallest (CondMin) or largest (CondMax) values along a given index, but only along a subset of values as indicated by the parameter cond.

When no cell satisfies «cond», the result of CondMax is -INF, and the result of CondMin is INF.

Starting with 4.4, CondMax and CondMin support the named parameter syntax and allow multiple indexes to be listed. The optional flag parameter «caseInsensitive» can be set to true (default is False).

Related Functions

Comments


You are not allowed to post comments.