simple-squiggle

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

evaluate.md (1228B)


      1 <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
      2 
      3 # Function evaluate
      4 
      5 Evaluate an expression.
      6 
      7 Note the evaluating arbitrary expressions may involve security risks,
      8 see [https://mathjs.org/docs/expressions/security.html](https://mathjs.org/docs/expressions/security.html) for more information.
      9 
     10 
     11 ## Syntax
     12 
     13 ```js
     14 math.evaluate(expr)
     15 math.evaluate(expr, scope)
     16 math.evaluate([expr1, expr2, expr3, ...])
     17 math.evaluate([expr1, expr2, expr3, ...], scope)
     18 ```
     19 
     20 ### Parameters
     21 
     22 Parameter | Type | Description
     23 --------- | ---- | -----------
     24 `expr` | string &#124; string[] &#124; Matrix | The expression to be evaluated
     25 `scope` | Object | Scope to read/write variables
     26 
     27 ### Returns
     28 
     29 Type | Description
     30 ---- | -----------
     31 * | The result of the expression
     32 
     33 
     34 ### Throws
     35 
     36 Type | Description
     37 ---- | -----------
     38 Error | 
     39 
     40 ## Examples
     41 
     42 ```js
     43 math.evaluate('(2+3)/4')                // 1.25
     44 math.evaluate('sqrt(3^2 + 4^2)')        // 5
     45 math.evaluate('sqrt(-4)')               // 2i
     46 math.evaluate(['a=3', 'b=4', 'a*b'])    // [3, 4, 12]
     47 
     48 let scope = {a:3, b:4}
     49 math.evaluate('a * b', scope)           // 12
     50 ```
     51 
     52 
     53 ## See also
     54 
     55 [parse](parse.md),
     56 [compile](compile.md)