1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | const math = require('../index')
|
9 |
|
10 |
|
11 | console.log('simplify expressions')
|
12 | console.log(math.simplify('3 + 2 / 4').toString())
|
13 | console.log(math.simplify('2x + 3x').toString())
|
14 | console.log(math.simplify('2 * 3 * x', {x: 4}).toString())
|
15 | console.log(math.simplify('x^2 + x + 3 + x^2').toString())
|
16 | console.log(math.simplify('x * y * -x / (x ^ 2)').toString())
|
17 |
|
18 |
|
19 | const f = math.parse('2x + x')
|
20 | const simplified = math.simplify(f)
|
21 | console.log(simplified.toString())
|
22 | console.log(simplified.eval({x: 4}))
|
23 | console.log()
|
24 |
|
25 |
|
26 | console.log('calculate derivatives')
|
27 | console.log(math.derivative('2x^2 + 3x + 4', 'x').toString())
|
28 | console.log(math.derivative('sin(2x)', 'x').toString())
|
29 |
|
30 |
|
31 | const h = math.parse('x^2 + x')
|
32 | const dh = math.derivative(h, 'x')
|
33 | console.log(dh.toString())
|
34 | console.log(dh.eval({x: 3}))
|