min

min(x, y, ...)

Return the minimum of the arguments. Operates elementwise over arrays.

Examples

julia> x = rand(5)
       y = rand(5)
       min(x,y)
5-element Array{Float64,1}:
 0.470566 
 0.0918323
 0.106548 
 0.28768  
 0.0033303
  1. Find the minimum value of two numbers:

    julia> min(5, 3)
    3

    This example returns the minimum value between 5 and 3.

  2. Find the minimum value among multiple numbers:

    julia> min(10, 7, 15, 4)
    4

    It calculates the minimum value among the provided numbers.

  3. Find the minimum value in an array:

    julia> arr = [5, 3, 9, 1, 7];
    julia> min(arr...)
    1

    This example uses the splat operator ... to pass the array as separate arguments to the min function.

  4. Find the minimum value elementwise between arrays:
    julia> arr1 = [2, 4, 6];
    julia> arr2 = [1, 5, 3];
    julia> min(arr1, arr2)
    3-element Array{Int64,1}:
    1
    4
    3

    It calculates the elementwise minimum between the corresponding elements of arr1 and arr2.

Common mistake example:

julia> min([5, 2, 7])
ERROR: MethodError: no method matching min(::Array{Int64,1})

In this example, the mistake is passing an array directly to the min function instead of using the splat operator .... The correct approach is to use min(arr...) to calculate the minimum value among the elements of the array.

See Also

abs2, beta, binomial, ceil, cell, cross, ctranspose, ctranspose!, cummin, cumprod, cumprod!, cumsum, cumsum!, cumsum_kbn, div, divrem, eigfact, eigfact!, eigmin, eps, erf, erfc, erfcinv, erfcx, erfi, erfinv, exp, exp10, exp2, expm1, exponent, factor, factorial, factorize, floor, gcd, invmod, log, log10, log1p, log2, logspace, max, min, mod, mod1, modf, next, nextpow, nextprod, num, primes, primesmask, prod, realmin, sqrt, sum!, sumabs, sumabs!, sumabs2, sumabs2!,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: