var invert = require('./matrix-invert.js'); var matrices = []; const POLYGONAL = 'polygonal', EQUIDISTANT = 'equidistant'; var binomialCoefficients = [[1],[1,1]]; function binomial(n,k) { if (n===0) return 1; var lut = binomialCoefficients; while(n >= lut.length) { var s = lut.length; var nextRow = [1]; for(var i=1,prev=s-1; i Mt.push([])); M.forEach((row,r) => row.forEach((v,c) => Mt[c][r] = v)); return Mt; } function row(M,i) { return M[i]; } function col(M,i) { var col = []; for(var r=0, l=M.length; r a + _col[i]*v; M[r][c] = _row.reduce(reducer, 0); } } return M; } function getValueColumn(P, prop) { var col = []; P.forEach(v => col.push([v[prop]])); return col; } function computeBasisMatrix(n) { /* We can form any basis matrix using a generative approach: - it's an M = (n x n) matrix - it's a lower triangular matrix: all the entries above the main diagonal are zero - the main diagonal consists of the binomial coefficients for n - all entries are symmetric about the antidiagonal. What's more, if we number rows and columns starting at 0, then the value at position M[r,c], with row=r and column=c, can be expressed as: M[r,c] = (r choose c) * M[r,r] * S, where S = 1 if r+c is even, or -1 otherwise That is: the values in column c are directly computed off of the binomial coefficients on the main diagonal, through multiplication by a binomial based on matrix position, with the sign of the value also determined by matrix position. This is actually very easy to write out in code: */ // form the square matrix, and set it to all zeroes var M = [], i = n; while (i--) { M[i] = "0".repeat(n).split('').map(v => parseInt(v)); } // populate the main diagonal var k = n - 1; for (i=0; i { S[i] = v/len; }); return S; } computeTimeValues[EQUIDISTANT] = function computeEquidistantTimeValues(P, n) { return '0'.repeat(n).split('').map((_,i) =>i/(n-1)); } function raiseRowPower(row, i) { return row.map(v => Math.pow(v,i)); } function formTMatrix(S, n) { n = n || S.length; var Tp = []; // it's easier to generate the transposed matrix: for(var i=0; i