实现基本的元素矩阵 - 矩阵和标量矩阵运算。
实行:
:: *另外
:: *减法
:: *乘法
:: *分裂
:: *取幂
第一个参数是要执行的操作,例如:用于矩阵加法的“m_add”和用于标量加法的“s_add”。第二和第三参数将是要在其上执行操作的矩阵。
operation
是一种功能。
testString: assert(typeof operation === 'function');
- text: operation("m_add",[[1,2],[3,4]],[[1,2],[3,4]])
应返回[[2,4],[6,8]]
。
testString: assert.deepEqual(operation('m_add', [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[2, 4], [6, 8]]);
- text: operation("s_add",[[1,2],[3,4]],[[1,2],[3,4]])
应返回[[3,4],[5,6]]
。
testString: assert.deepEqual(operation('s_add', [[1, 2], [3, 4]], 2), [[3, 4], [5, 6]]);
- text: operation("m_sub",[[1,2],[3,4]],[[1,2],[3,4]])
应返回[[0,0],[0,0]]
。
testString: assert.deepEqual(operation('m_sub', [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[0, 0], [0, 0]]);
- text: operation("m_mult",[[1,2],[3,4]],[[1,2],[3,4]])
应该返回[[1,4],[9,16]]
。
testString: assert.deepEqual(operation('m_mult', [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[1, 4], [9, 16]]);
- text: operation("m_div",[[1,2],[3,4]],[[1,2],[3,4]])
应返回[[1,1],[1,1]]
。
testString: assert.deepEqual(operation('m_div', [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[1, 1], [1, 1]]);
- text: operation("m_exp",[[1,2],[3,4]],[[1,2],[3,4]])
应返回[[1,4],[27,256]]
。
testString: assert.deepEqual(operation('m_exp', [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[1, 4], [27, 256]]);
- text: operation("m_add",[[1,2,3,4],[5,6,7,8]],[[9,10,11,12],[13,14,15,16]])
应该返回[[10,12,14,16],[18,20,22,24]]
。
testString: assert.deepEqual(operation('m_add', [[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]), [[10, 12, 14, 16], [18, 20, 22, 24]]);
```