add.md (1345B)
1 <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. --> 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 ### Throws 31 32 Type | Description 33 ---- | ----------- 34 35 36 ## Examples 37 38 ```js 39 math.add(2, 3) // returns number 5 40 math.add(2, 3, 4) // returns number 9 41 42 const a = math.complex(2, 3) 43 const b = math.complex(-4, 1) 44 math.add(a, b) // returns Complex -2 + 4i 45 46 math.add([1, 2, 3], 4) // returns Array [5, 6, 7] 47 48 const c = math.unit('5 cm') 49 const d = math.unit('2.1 mm') 50 math.add(c, d) // returns Unit 52.1 mm 51 52 math.add("2.3", "4") // returns number 6.3 53 ``` 54 55 56 ## See also 57 58 [subtract](subtract.md), 59 [sum](sum.md)