1 |
|
2 |
|
3 | # Function add
|
4 |
|
5 | Add two or more values, `x + y`.
|
6 | For matrices, the function is evaluated element wise.
|
7 |
|
8 |
|
9 | ## Syntax
|
10 |
|
11 | ```js
|
12 | math.add(x, y)
|
13 | math.add(x, y, z, ...)
|
14 | ```
|
15 |
|
16 | ### Parameters
|
17 |
|
18 | Parameter | Type | Description
|
19 | --------- | ---- | -----------
|
20 | `x` | number | BigNumber | Fraction | Complex | Unit | Array | Matrix | First value to add
|
21 | `y` | number | BigNumber | Fraction | Complex | Unit | Array | Matrix | Second value to add
|
22 |
|
23 | ### Returns
|
24 |
|
25 | Type | Description
|
26 | ---- | -----------
|
27 | number | BigNumber | Fraction | Complex | Unit | Array | Matrix | Sum of `x` and `y`
|
28 |
|
29 |
|
30 | ## Examples
|
31 |
|
32 | ```js
|
33 | math.add(2, 3) // returns number 5
|
34 | math.add(2, 3, 4) // returns number 9
|
35 |
|
36 | const a = math.complex(2, 3)
|
37 | const b = math.complex(-4, 1)
|
38 | math.add(a, b) // returns Complex -2 + 4i
|
39 |
|
40 | math.add([1, 2, 3], 4) // returns Array [5, 6, 7]
|
41 |
|
42 | const c = math.unit('5 cm')
|
43 | const d = math.unit('2.1 mm')
|
44 | math.add(c, d) // returns Unit 52.1 mm
|
45 |
|
46 | math.add("2.3", "4") // returns number 6.3
|
47 | ```
|
48 |
|
49 |
|
50 | ## See also
|
51 |
|
52 | [subtract](subtract.md),
|
53 | [sum](sum.md)
|