Skip to content

Instantly share code, notes, and snippets.

@ncalm
Created October 25, 2024 15:37
Show Gist options
  • Save ncalm/91c9d2f2c12f1ba5a8b685b8f5726f41 to your computer and use it in GitHub Desktop.
Save ncalm/91c9d2f2c12f1ba5a8b685b8f5726f41 to your computer and use it in GitHub Desktop.
This Excel LAMBDA function computes the finite difference of a vector
/*
FINITE_DIFF function
array is a vector (one column or one row)
1) Check if array is a vector. If not, return #VALUE!
2) Multiply array by similarly sized array of {1, -1, ..., -1}.
3) REDUCE SUM over (2)
*/
FINITE_DIFF = LAMBDA(array,
IF(
AND(ROWS(array)>1,COLUMNS(array)>1), #VALUE!,
REDUCE(,array * EXPAND(1, ROWS(array), COLUMNS(array), -1), SUM)
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment