ISUNIFORM
=ISUNIFORM(vector, [precision_n])
Argument | Description | Example |
---|---|---|
vector | The sequence of values you want to check | {2; 3; 4; 5} |
precision_n | The precision (number of decimal places) to use for evaluating equality of step sizes | 10 |
Description
ISUNIFORM returns {TRUE;step} if the values in the vector are evenly spaced (all steps are identical). If FALSE, it returns {FALSE; MAX(step)-MIN(step)}.
You can set the precision_n parameter to be a number of decimal places (such as 10), and the step size will be rounded to that number of decimal places prior to testing for uniformity.
Purpose of precision_n: In some cases, precision errors in Excel may cause this function to return FALSE when you might otherwise consider the uniformity to be "close enough." For example, if MAX(step)-MIN(step) is a number smaller than 1E-10, it might be a precision error, and you might determine that a difference in step size smaller than 1E-10 is sufficient to consider the vector uniform.
In Excel, make the function return only a single value by using the @ symbol in front of the function: =@ISUNIFORM(...).
Lambda Formula
This code for using ISUNIFORM in Excel is provided under the License as part of the LAMBDA Library, but to use just this function, you may copy the following code directly into your spreadsheet.
Code to Create Function via the Name Manager
Name: ISUNIFORM
Comment: Returns {TRUE;step} if the vector is uniformly spaced
Refers To:
=LAMBDA(vector,[precision_n],
LET(doc,"https://www.vertex42.com/lambda/isuniform.html",
rows,ROWS(vector),cols,COLUMNS(vector),
vector,TAKE(IF(AND(cols>1,rows=1),TRANSPOSE(vector),vector),,1),
steps,DROP(vector,1)-DROP(vector,-1),
unique_steps,UNIQUE(IF(ISOMITTED(precision_n),steps,ROUND(steps,precision_n))),
IF(ROWS(unique_steps)=1,
TRUE,
VSTACK(FALSE,MAX(unique_steps)-MIN(unique_steps))
)
))
Code for AFE Workbook Module (Excel Labs Add-in)
/** * Returns {TRUE;step} if the vector is uniformly spaced (all the * steps are identical to a precision of n decimal places) * If FALSE, returns {FALSE, MAX(steps)-MIN(steps)} */ ISUNIFORM = LAMBDA(vector,[precision_n], LET(doc,"https://www.vertex42.com/lambda/isuniform.html", rows,ROWS(vector),cols,COLUMNS(vector), vector,TAKE(IF(AND(cols>1,rows=1),TRANSPOSE(vector),vector),,1), steps,DROP(vector,1)-DROP(vector,-1), unique_steps,UNIQUE(IF(ISOMITTED(precision_n),steps,ROUND(steps,precision_n))), IF(ROWS(unique_steps)=1, TRUE, VSTACK(FALSE,MAX(unique_steps)-MIN(unique_steps)) ) ));
Named Function for Google Sheets
Name: ISUNIFORM Description: Returns {TRUE;step} if the vector is uniformly spaced (steps are identical). If FALSE, returns {FALSE, MAX(steps)-MIN(steps)} Arguments: vector, precision_n Function: LET(doc,"https://www.vertex42.com/lambda/isuniform.html", r,ROWS(vector), steps,ARRAYFORMULA(CHOOSEROWS(vector,SEQUENCE(r-1,1,2))-CHOOSEROWS(vector,SEQUENCE(r-1,1,1))), unique_steps,UNIQUE(IF(ISBLANK(precision_n),steps,ARRAYFORMULA(ROUND(steps,precision_n)))), ret,IF(ROWS(unique_steps)=1,TRUE,VSTACK(FALSE,MAX(unique_steps)-MIN(unique_steps))), ret )
ISUNIFORM Examples
Test: Copy and Paste this LET function into a cell =LET( vector, LINSPACE(1,2,4), ISUNIFORM(vector) ) Result: TRUE =LET( vector, {1; 1.333333; 1.666667; 2}, ISUNIFORM(vector) ) Result: {FALSE; 1E-6}
Test: Copy and Paste this LET function into a cell =LET( logseq, LOGSPACE(1,2,5), ISUNIFORM(LOG10(logseq)) ) Result: {FALSE; 4.4409E-16}
In this case, if you set the precision_n parameter to 14, then the Result will be TRUE.
SE, LINSPACE, LOGSPACE, RESCALE, ISUNIFORM