static/js/numeric.js
/**
 * Generate an identity matrix.
 * @function idMat
 * @param {number} n - size of the matrix
 * @return {number[]} the identity matrix
 * @description An identity matrix is a square matrix with 1 on the diagonal
 * and 0 elsewhere.
 * @see {@link https://en.wikipedia.org/wiki/Identity_matrix}
 * @see numpy.identity
 */
Generate an identity matrix.
@function idMat
@param {number} n - size of the matrix
@return {number[]} the identity matrix
@description An identity matrix is a square matrix with 1 on the diagonal
and 0 elsewhere.
Generate an identity matrix . @function idMat @param { number } n - size of the matrix @return { number [] } the identity matrix @description An identity matrix is a square matrix with 1 on the diagonal and 0 elsewhere .
function idMat(n) {
  const res = Array(n).fill().map(() => Array(n).fill(0));
  for (let i = 0; i < n; i++) {
    res[i][i] = 1;
  }
  return res;
}
function idMat ( n ) { const res = Array ( n ) . fill ( ) . map ( ( ) => Array ( n ) . fill ( 0 ) ) ; for ( let i = 0 ; i < n ; i ++ ) { res [ i ] [ i ] = 1 ; } return res ; }
Generate an identity matrix.
Generate an identity matrix .