1 |
|
2 |
|
3 |
|
4 | const math = require('..')
|
5 |
|
6 |
|
7 | console.log('functions and constants')
|
8 | print(math.round(math.e, 3))
|
9 | print(math.atan2(3, -3) / math.pi)
|
10 | print(math.log(10000, 10))
|
11 | print(math.sqrt(-4))
|
12 | print(math.pow([[-1, 2], [3, 1]], 2))
|
13 | print(math.derivative('x^2 + x', 'x'))
|
14 | console.log()
|
15 |
|
16 |
|
17 | console.log('expressions')
|
18 | print(math.evaluate('1.2 * (2 + 4.5)'))
|
19 | print(math.evaluate('12.7 cm to inch'))
|
20 | print(math.evaluate('sin(45 deg) ^ 2'))
|
21 | print(math.evaluate('9 / 3 + 2i'))
|
22 | print(math.evaluate('det([-1, 2; 3, 1])'))
|
23 | console.log()
|
24 |
|
25 |
|
26 | console.log('chained operations')
|
27 | const a = math.chain(3)
|
28 | .add(4)
|
29 | .multiply(2)
|
30 | .done()
|
31 | print(a)
|
32 | console.log()
|
33 |
|
34 |
|
35 | console.log('mixed use of data types')
|
36 | print(math.add(4, [5, 6]))
|
37 | print(math.multiply(math.unit('5 mm'), 3))
|
38 | print(math.subtract([2, 3, 4], 5))
|
39 | print(math.add(math.matrix([2, 3]), [4, 5]))
|
40 | console.log()
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | function print (value) {
|
47 | const precision = 14
|
48 | console.log(math.format(value, precision))
|
49 | }
|