IsMonotonic - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


ArrayTools

  

IsMonotonic

  

determine if a 1-D list or rtable is decreasing, increasing, non-decreasing, or non-increasing

 

Calling Sequence

Parameters

Options

Description

Examples

Compatibility

Calling Sequence

IsMonotonic( data )

IsMonotonic( data, section )

Parameters

data

-

1-D list or rtable of data of type realcons

section

-

(optional) range of the form a..b, a.., ..b, or .., where a and b are integers. The default is .., which corresponds to the entire container.

Options

• 

direction: Either increasing or decreasing. The default is increasing.

• 

strict: Either true or false. The default is true.

Description

• 

The IsMonotonic command determines if a 1-D list or rtable, or a section of it, is monotonic (increasing, non-decreasing, decreasing, or non-increasing).

• 

If direction=increasing and strict=true, then the result is true if data[i+1]>data[i] for all valid indices i, and false otherwise.

• 

If direction=increasing and strict=false, then the result is true if data[i+1]>=data[i] for all valid indices i, and false otherwise.

• 

If direction=decreasing and strict=true, then the result is true if data[i+1]<data[i] for all valid indices i, and false otherwise.

• 

If direction=decreasing and strict=false, then the result is true if data[i+1]<=data[i] for all valid indices i, and false otherwise.

• 

If data has fewer than two elements, or the section contains fewer than two elements, the result is vacuously true.

• 

If data is not an Array with lower index different than 1, you can use valid negative indices in section for counting backward. For example, if data is a Vector with 15 elements, then 5..-2 is a valid range for section (equivalent to 5..14), with -2 indicating the second element from the end. However, if data is an Array with lower index different than 1, you can only use valid literal indices.

• 

Suppose the working precision of the session is larger than that of hardware floats (i.e. Digits>evalhf(Digits)), or use of hardware floats has been disabled (i.e. UseHardwareFloats=false). Here, IsMonotonic will use external code to determine monotonicity.

Examples

withArrayTools&colon;

Example 1

• 

Strictly increasing list:

A5&comma;10&comma;15&comma;20

A5&comma;10&comma;15&comma;20

(1)

dataplotA&comma;view=0..5&comma;0..20&comma;color=blue

IsMonotonicA&comma;direction=increasing&comma;strict=true

true

(2)

IsMonotonicA&comma;direction=decreasing&comma;strict=true

false

(3)

Example 2

• 

Increasing but not strictly increasing:

B5&comma;10&comma;10&comma;20

B5&comma;10&comma;10&comma;20

(4)

dataplotB&comma;view=0..5&comma;0..20&comma;color=blue

IsMonotonicB&comma;direction=increasing&comma;strict=true

false

(5)

IsMonotonicB&comma;direction=increasing&comma;strict=false

true

(6)

Example 3

• 

Not monotonic on the whole, but monotonic on subsections:

CArray2&comma;3&comma;4&comma;5&comma;4&comma;3&comma;2&comma;3&comma;4&comma;5

C2345432345

(7)

dataplotC&comma;view=0..10&comma;0..5&comma;color=blue

IsMonotonicC&comma;direction=increasing&comma;strict=false

false

(8)

IsMonotonicC&comma;..4&comma;direction=increasing&comma;strict=true

true

(9)

IsMonotonicC&comma;4..7&comma;direction=decreasing&comma;strict=true

true

(10)

IsMonotonicC&comma;7..1&comma;direction=increasing&comma;strict=true

true

(11)

Example 4

• 

Data can include infinity:

L&comma;0&comma;

L&comma;0&comma;

(12)

IsMonotonicL&comma;direction=increasing

true

(13)

IsMonotonicL&comma;direction=decreasing

false

(14)

Example 5

• 

Consider the following long Array:

dataArray1..104&comma;ii&comma;datatype=float8&colon;

• 

The Array is strictly increasing, and confirmation using the IsMonotonic command requires checking the elements all the way to the end:

CodeTools:-UsageIsMonotonicdata

memory used=8.11KiB, alloc change=0 bytes, cpu time=0ns, real time=0ns, gc time=0ns

true

(15)

Compatibility

• 

Starting with Maple 2023, external C code is used for the auxiliary procedures that were formerly implemented in Maple and could be compiled by passing the compiled option. The compiled option is now deprecated, but it is still accepted for backwards compatibility.

• 

The ArrayTools[IsMonotonic] command was introduced in Maple 2021.

• 

For more information on Maple 2021 changes, see Updates in Maple 2021.

• 

The ArrayTools[IsMonotonic] command was updated in Maple 2023.

See Also

ArrayTools

dataplot