Difference between revisions of "Functions Min and Max"
m |
|||
Line 4: | Line 4: | ||
[[Category:Math Functions]] | [[Category:Math Functions]] | ||
− | = Functions Min and Max = | + | == Functions Min and Max == |
− | + | :<code>Min(X, I)</code> | |
− | + | :<code>Max(X, I)</code> | |
− | Returns the smallest (Min) or largest (Max) value in array | + | 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: | 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: | ||
− | + | :<code>Max([a, b, c])</code> | |
− | This form evaluates a, b, and c, and finds the largest value among them. For example: | + | This form evaluates <code>a, b</code>, and <code>c</code>, and finds the largest value among them. For example: |
− | + | :<code>Max([Sin(30), Tan(30), Cos(30)]) → 0.8660254</code> | |
− | Although index | + | 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, <code>J</code>. 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 | + | 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, |
− | + | :<code>Min(['A', 'B', 2]) → 'A'</code> | |
− | + | :<code>Max(['A', 'B', 2]) → 2</code> | |
− | It orders text as case sensitive unless you specify otherwise with the optional | + | |
+ | It orders text as case sensitive unless you specify otherwise with the optional «CaseInsensitive» parameter (see below). | ||
== Optional Parameters == | == Optional Parameters == | ||
− | |||
=== Multiple Indexes === | === Multiple Indexes === | ||
+ | :<code>Min(X, I, J, K, ...)</code> | ||
+ | :<code>Min(X, I, J, K, ...)</code> | ||
− | + | 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». | |
− | |||
− | |||
− | 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 | ||
=== Non-Numerics === | === Non-Numerics === | ||
− | + | :<code>Min(X, I'', IgnoreNonNumerics, IgnoreNaN'')</code> | |
− | + | :<code>Max(X, I'', IgnoreNonNumerics, IgnoreNaN'')</code> | |
− | If | + | If «IgnoreNonNumerics» is set to true (<code>1</code>), it ignores non-numeric values. |
− | If | + | If «IgnoreNAN» is set to true (1), it ignores [[NaN]] values. |
− | It always ignores [[ | + | It always ignores [[Null]] no matter what the parameter values. |
These optional Boolean parameters require a named-parameter syntax. | These optional Boolean parameters require a named-parameter syntax. | ||
− | :{| | + | :<code>Variable A :=</code> |
− | ! I & | + | :{| class="wikitable" |
+ | ! colspan="7" | I ▶ | ||
+ | |- | ||
+ | ! 1 || 2 || 3 || 4 || 5 || 6 || 7 | ||
|- | |- | ||
− | |||
| 56 || "a" || 4 || "1" || 3 || «null» || 45 | | 56 || "a" || 4 || "1" || 3 || «null» || 45 | ||
|} | |} | ||
− | :Min(A, I, IgnoreNonNumerics: True) &rarr 3 | + | :<code>Min(A, I, IgnoreNonNumerics: True) → 3</code> |
− | :Max(A, I, IgnoreNonNumerics: True) &rarr 56 | + | :<code>Max(A, I, IgnoreNonNumerics: True) → 56</code> |
− | 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. | + | 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 === | ||
− | 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' ]) → 'DeBois' | + | :<code>Min(['DeBois', 'Debbie', 'Debutante']) → 'DeBois'</code> |
− | :Min(['DeBois', 'Debbie', 'Debutante' ], CaseInsensitive: True) → 'Debbie' | + | :<code>Min(['DeBois', 'Debbie', 'Debutante'], CaseInsensitive: True) → 'Debbie'</code> |
− | = Functions CondMin and CondMax = | + | == Functions CondMin and CondMax == |
− | + | :<code>CondMin(X: Array[I]; cond: Boolean[I]; I: Index)</code> | |
− | + | :<code>CondMax(X: Array[I]; cond: Boolean[I]; I: Index)</code> | |
− | 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 | + | 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. | + | 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 | + | Starting with Analytica 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). |
− | = | + | == See Also== |
− | * [[Ana:Fn:ArgMin_and_ArgMax| ArgMin]] | + | * [[Ana:Fn:ArgMin_and_ArgMax| ArgMin]] |
+ | * [[Ana:Fn:ArgMin_and_ArgMax| ArgMax]] |
Revision as of 04:49, 12 January 2016
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]) → 'A'
Max(['A', 'B', 2]) → 2
It orders text as case sensitive unless you specify otherwise with the optional «CaseInsensitive» 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.
Variable A :=
I ▶ 1 2 3 4 5 6 7 56 "a" 4 "1" 3 «null» 45
Min(A, I, IgnoreNonNumerics: True) → 3
Max(A, I, IgnoreNonNumerics: True) → 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 Analytica 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).
Enable comment auto-refresher