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
35 lines
1.3 KiB
JavaScript
35 lines
1.3 KiB
JavaScript
// algebra
|
|
//
|
|
// math.js has support for symbolic computation (CAS). It can parse
|
|
// expressions in an expression tree and do algebraic operations like
|
|
// simplification and derivation on this tree.
|
|
|
|
// load math.js (using node.js)
|
|
const math = require('../index')
|
|
|
|
// simplify an expression
|
|
console.log('simplify expressions')
|
|
console.log(math.simplify('3 + 2 / 4').toString()) // '7 / 2'
|
|
console.log(math.simplify('2x + 3x').toString()) // '5 * x'
|
|
console.log(math.simplify('2 * 3 * x', { x: 4 }).toString()) // '24'
|
|
console.log(math.simplify('x^2 + x + 3 + x^2').toString()) // '2 * x ^ 2 + x + 3'
|
|
console.log(math.simplify('x * y * -x / (x ^ 2)').toString()) // '-y'
|
|
|
|
// work with an expression tree, evaluate results
|
|
const f = math.parse('2x + x')
|
|
const simplified = math.simplify(f)
|
|
console.log(simplified.toString()) // '3 * x'
|
|
console.log(simplified.eval({ x: 4 })) // 12
|
|
console.log()
|
|
|
|
// calculate a derivative
|
|
console.log('calculate derivatives')
|
|
console.log(math.derivative('2x^2 + 3x + 4', 'x').toString()) // '4 * x + 3'
|
|
console.log(math.derivative('sin(2x)', 'x').toString()) // '2 * cos(2 * x)'
|
|
|
|
// work with an expression tree, evaluate results
|
|
const h = math.parse('x^2 + x')
|
|
const dh = math.derivative(h, 'x')
|
|
console.log(dh.toString()) // '2 * x + 1'
|
|
console.log(dh.eval({ x: 3 })) // '7'
|