simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

basic_usage.html (1013B)


      1 <!DOCTYPE html>
      2 <html lang="en">
      3 <head>
      4   <meta charset="utf-8">
      5   <title>math.js | basic usage</title>
      6   <script src="../../lib/browser/math.js"></script>
      7 </head>
      8 <body>
      9 
     10 <script>
     11   function print(value) {
     12     const precision = 14
     13     document.write(math.format(value, precision) + '<br>')
     14   }
     15 
     16   // functions and constants
     17   print(math.round(math.e, 3))            // 2.718
     18   print(math.atan2(3, -3) / math.pi)      // 0.75
     19   print(math.log(10000, 10))              // 4
     20   print(math.sqrt(-4))                    // 2i
     21   print(math.pow([[-1, 2], [3, 1]], 2))   // [[7, 0], [0, 7]]
     22   print(math.derivative('x^2 + x', 'x'))  // 2 * x + 1
     23 
     24   // expressions
     25   print(math.evaluate('12 / (2.3 + 0.7)'))    // 4
     26   print(math.evaluate('12.7 cm to inch'))     // 5 inch
     27   print(math.evaluate('9 / 3 + 2i'))          // 3 + 2i
     28   print(math.evaluate('det([-1, 2; 3, 1])'))  // -7
     29 
     30   // chained operations
     31   const a = math.chain(3)
     32       .add(4)
     33       .multiply(2)
     34       .done()
     35   print(a)  // 14
     36 </script>
     37 
     38 </body>
     39 </html>