abs function
float abs(x)
float[] abs(x)
x floatfloat[]
Returns the absolute value of x. For arrays, the function is applied element-wise and returns a new array with the absolute values.
Related
Example
findAll(array, value, epsilon) =
[0 : size(array)-1][abs(array .- value) .<= epsilon]
getValues(array, value, epsilon) =
array[abs(array .- value) .<= epsilon]
const sequence = [0 : 0.1 : 2]
Lot --> print( findFirst(sequence, 1, 0.15) ) // 9
print( sequence[ findFirst(sequence, 1, 0.15) ] ) // 0.9
print( findAll (sequence, 1, 0.15) ) // (3)[9,10,11]
print( sequence[ findAll (sequence, 1, 0.15) ] ) // (3)[0.9,1,1.1]
print( getValues(sequence, 1, 0.15) ) // (3)[0.9,1,1.1]
Using the abs function to find values in an array within a tolerance epsilon. In contrast to the findFirst function, findAll returns all found indices.