mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-18 14:59:29 +00:00
* chore(package): update standard to version 12.0.0
* update to new lint version with --fix
I believe this mainly adds whitespace to `{}`'s.
* Replace assert.equal with assert.strictEqual
This breaks a lot of tests which I will endevour to fix in the next
commits.
* Fix most errors due to assert.strictEquals
Some instances of `strictEquals` are replaced by `deepEquals`.
`toString` has been used to make some string comparisions explicit.
Tests will still fail untill #1236 and #1237 are fixed.
* Fix assertion erros due to -0
With node 10, assert.strictEqual no longer considers `0 === -0`.
I missed these first time round as I was using node 8.
* Put toString correct side of bracket
I was converting the constructor to a string rather
than the result of the computation. Oops.
* Fixed #1236: quantileSeq has inconsistant return
* Update package-lock
* Fixed #1237: norm sometimes returning a complex number instead of number
* Fix cli tests
* More changes for standardjs, and fixes in unit tests
93 lines
2.1 KiB
JavaScript
93 lines
2.1 KiB
JavaScript
// test expm
|
|
const assert = require('assert')
|
|
const approx = require('../../../tools/approx')
|
|
const math = require('../../../src/main')
|
|
const expm = math.expm
|
|
|
|
describe('expm', function () {
|
|
it('should only accept a square matrix', function () {
|
|
assert.throws(function () { expm(5) }, /Unexpected type/)
|
|
assert.throws(function () { expm([1, 2]) }, /Matrix must be square/)
|
|
assert.throws(function () { expm([[1, 2]]) }, /Matrix must be square/)
|
|
assert.throws(function () { expm([[1, 2, 3], [4, 5, 6]]) }, /Matrix must be square/)
|
|
})
|
|
|
|
it('should compute the exponential of a matrix', function () {
|
|
// Trivial example
|
|
approx.deepEqual(expm(
|
|
[[1, 0],
|
|
[0, 1]]
|
|
),
|
|
math.matrix(
|
|
[[2.718281828, 0],
|
|
[0, 2.718281828]]
|
|
))
|
|
|
|
// Example given in the Moler and Van Loan paper
|
|
approx.deepEqual(expm(
|
|
[[-49, 24],
|
|
[-64, 31]]
|
|
),
|
|
math.matrix(
|
|
[[-0.735759, 0.551819],
|
|
[-1.471518, 1.103638]]
|
|
))
|
|
|
|
// Another example from the same paper
|
|
approx.deepEqual(expm(
|
|
[[0, 6, 0, 0],
|
|
[0, 0, 6, 0],
|
|
[0, 0, 0, 6],
|
|
[0, 0, 0, 0]]
|
|
),
|
|
math.matrix(
|
|
[[1, 6, 18, 36],
|
|
[0, 1, 6, 18],
|
|
[0, 0, 1, 6],
|
|
[0, 0, 0, 1]]
|
|
))
|
|
|
|
// And another
|
|
approx.deepEqual(expm(
|
|
[[1, 1],
|
|
[0, 1]]
|
|
),
|
|
math.matrix(
|
|
[[2.718282, 2.718282],
|
|
[0, 2.718282]]
|
|
))
|
|
|
|
// And another
|
|
approx.deepEqual(expm(
|
|
[[1 + 1e-5, 1],
|
|
[0, 1 - 1e-5]]
|
|
),
|
|
math.matrix(
|
|
[[2.718309, 2.718282],
|
|
[0, 2.718255]]
|
|
))
|
|
})
|
|
|
|
it('should work on SparseMatrix', function () {
|
|
approx.deepEqual(expm(
|
|
math.sparse(
|
|
[[0, 6, 0, 0],
|
|
[0, 0, 6, 0],
|
|
[0, 0, 0, 6],
|
|
[0, 0, 0, 0]]
|
|
)
|
|
),
|
|
math.sparse(
|
|
[[1, 6, 18, 36],
|
|
[0, 1, 6, 18],
|
|
[0, 0, 1, 6],
|
|
[0, 0, 0, 1]]
|
|
))
|
|
})
|
|
|
|
it('should LaTeX transpose', function () {
|
|
const expression = math.parse('expm([[1,2],[3,4]])')
|
|
assert.strictEqual(expression.toTex(), '\\exp\\left(\\begin{bmatrix}1&2\\\\3&4\\\\\\end{bmatrix}\\right)')
|
|
})
|
|
})
|