Main Content

min

Minimum elements of symbolic input

Description

M = min(A) returns the minimum elements of a symbolic input.

  • If A is a vector, then min(A) returns the minimum of A.

  • If A is a matrix, then min(A) is a row vector containing the minimum value of each column of A.

For an input A that contains a symbolic expression, the symbolic min function returns an unevaluated expression that excludes elements in A that do not represent minimum values. The output might have another argument that represents the condition for the symbolic variable. For example, syms x; min([1 x]) returns the output min([1, x], [], 2, 'omitnan', ~in(x, 'real')) in the Command Window because x is complex.

example

M = min(A,[],"all") returns the minimum over all elements of A.

example

M = min(A,[],dim) returns the minimum element along dimension dim. For example, if A is a matrix, then min(A,[],2) returns a column vector containing the minimum value of each row.

example

M = min(A,[],___,nanflag) specifies whether to include or omit NaN values in A for any of the previous syntaxes. For example, min(A,[],"includenan") includes all NaN values when computing the minimum, while min(A,[],"omitnan") ignores all NaN values.

example

[M,I] = min(___) also returns the index into the operating dimension that corresponds to the first occurrence of the minimum value of A.

example

C = min(A,B) returns an array containing the smallest elements taken from A or B.

example

C = min(A,B,nanflag) also specifies how to treat NaN values.

Examples

collapse all

Create a symbolic vector of real elements. Find the smallest real element using the symbolic min function.

syms x real
A = [23 42 37 18 x];
M = min(A)
M = min([18,x],[],2,"omitnan",symfalse)

The symbolic min function returns an unevaluated expression. The expression excludes elements in A that do not represent minimum values.

Create a symbolic vector and compute its minimum, excluding NaN values.

syms x positive
A = [1.75 x 3.25 -2.5 NaN 0.5 NaN 0.2 -4*x];
M = min(A,[],"omitnan")
M = 

min([-52,-4x],[],2,"omitnan",symfalse)

min(A) also produces this result because "omitnan" is the default option.

Use the "includenan" option to return NaN.

M = min(A,[],"includenan")
M = NaN

Create a symbolic matrix and find the smallest element in each column.

syms x real
A = [1 x -0.5; -2 1 x]
A = 

(1x-12-21x)

M = min(A)
M = 

(-2min([1,x],[],2,"omitnan",symfalse)min([-12,x],[],2,"omitnan",symfalse))

Create a symbolic matrix and find the smallest element in each row.

syms x real
A = [1 x -0.5; -2 1 x]
A = 

(1x-12-21x)

M = min(A,[],2)
M = 

(min([-12,x],[],2,"omitnan",symfalse)min([-2,x],[],2,"omitnan",symfalse))

Create a symbolic matrix A. Find the smallest elements in each row of A and return the column indices corresponding to the first occurrence of the minimum value in each row. Because A contains a symbolic variable x with an undetermined value, min cannot explicitly evaluate the minimum value in each row and returns the indices as -1.

syms x real
A = [1 x -0.5; -2 2 x]
A = 

(1x-12-22x)

[M,I] = min(A,[],2)
M = 

(min([-12,x],[],2,"omitnan",symfalse)min([-2,x],[],2,"omitnan",symfalse))

I = 2×1

    -1
    -1

Substitute a symbolic number for the variable x in the symbolic matrix A. Find the smallest elements in each row again. Here, min is able to evaluate the minimum values and returns the column indices corresponding to the first occurrence of the minimum value in each row.

A = subs(A,x,sqrt(2))
A = 

(12-12-222)

[M,I] = min(A,[],2)
M = 

(-12-2)

I = 2×1

     3
     1

Create a symbolic matrix. Find the minimum over all dimensions of the matrix by using the min function with the "all" option.

syms x real
A = [1 x -0.5; -2 1 x]
A = 

(1x-12-21x)

M = min(A,[],"all")
M = min([-2,x],[],2,"omitnan",symfalse)

Create two symbolic matrices with complex elements. Find the smallest elements taken from the two matrices. The largest elements are the complex values with the smallest magnitude.

syms x y
A = [x 2+1i; 3 4i; -5 y]
A = 

(x2+i34i-5y)

B = [1 y; 2i 1+1i; -3 x]
B = 

(1y2i1+i-3x)

C = min(A,B)
C = 

(min([1,x],[],2,"omitnan",xR)min([2+i,y],[],2,"omitnan",symtrue)2i1+i-3min([x,y],[],2,"omitnan",xRyR))

Define the following expression by using the symbolic min function. Assume that the variable x is real.

f(x)={0x>11-xx<1

syms x real
f(x) = sqrt(1 - min(x,1))
f(x) = 1-min([1,x],[],2,"omitnan",symfalse)

Plot the expression by using fplot.

fplot(f,[-5 5])

Figure contains an axes object. The axes object contains an object of type functionline.

Input Arguments

collapse all

Input array, specified as a symbolic expression, vector of symbolic expressions, or matrix of symbolic expressions.

  • If A is complex, then min(A) returns the complex number with the smallest magnitude. If magnitudes are equal, then min(A) returns the value with the smallest magnitude and the smallest phase angle.

  • If A is a scalar, then min(A) returns A.

  • If A is a 0-by-0 empty array, then min(A) is an empty array as well.

Data Types: sym | single | double
Complex Number Support: Yes

Dimension to operate along, specified as a positive integer scalar. If you do not specify a value, then the default is the first array dimension whose size does not equal 1.

Dimension dim indicates the dimension whose length reduces to 1. So, size(M,dim) is 1, while the sizes of all other dimensions remain the same, unless size(A,dim) is 0. If size(A,dim) is 0, then min(A,dim) returns an empty array with the same size as A.

Consider a two-dimensional input array, A:

  • If dim = 1, then min(A,[],1) returns a row vector containing the smallest element in each column.

    min(A,[],1) column-wise operation

  • If dim = 2, then min(A,[],2) returns a column vector containing the smallest element in each row.

    min(A,[],2) row-wise operation

min returns A if dim is greater than ndims(A).

NaN condition, specified as one of these values:

  • "omitnan" — Ignore all NaN values in the input. If all elements are NaN, then min returns the first one.

  • "includenan" — Include the NaN values in the input for the calculation.

Additional input array, specified as a symbolic expression, vector of symbolic expressions, or matrix of symbolic expressions. Inputs A and B must either be the same size or have sizes that are compatible (for example, A is an M-by-N matrix and B is a scalar or 1-by-N row vector). For more information, see Compatible Array Sizes for Basic Operations.

Data Types: sym | single | double
Complex Number Support: Yes

Output Arguments

collapse all

Minimum values, returned as a symbolic expression, vector of symbolic expressions, or matrix of symbolic expressions. size(M,dim) is 1, while the sizes of all other dimensions match the size of the corresponding dimension in A, unless size(A,dim) is 0. If size(A,dim) is 0, then M is an empty array with the same size as A.

Index, returned as a scalar, vector, or matrix. I is the same size as the output M.

If the smallest element occurs more than once, then I contains the index to the first occurrence of the value.

Data Types: double

Minimum elements from A or B, returned as a symbolic expression, vector of symbolic expressions, or matrix of symbolic expressions. The size of C is determined by implicit expansion of the dimensions of A and B. For more information, see Compatible Array Sizes for Basic Operations.

Version History

Introduced in R2021a

expand all

See Also

Functions