UNPKG

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