UNPKG

mathjs

Version:

Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with dif

39 lines (34 loc) 1.01 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>math.js | basic usage</title> <script src="../../lib/browser/math.js"></script> </head> <body> <script> function print(value) { const precision = 14 document.write(math.format(value, precision) + '<br>') } // functions and constants print(math.round(math.e, 3)) // 2.718 print(math.atan2(3, -3) / math.pi) // 0.75 print(math.log(10000, 10)) // 4 print(math.sqrt(-4)) // 2i print(math.pow([[-1, 2], [3, 1]], 2)) // [[7, 0], [0, 7]] print(math.derivative('x^2 + x', 'x')) // 2 * x + 1 // expressions print(math.evaluate('12 / (2.3 + 0.7)')) // 4 print(math.evaluate('12.7 cm to inch')) // 5 inch print(math.evaluate('9 / 3 + 2i')) // 3 + 2i print(math.evaluate('det([-1, 2; 3, 1])')) // -7 // chained operations const a = math.chain(3) .add(4) .multiply(2) .done() print(a) // 14 </script> </body> </html>