1 |
|
2 |
|
3 | # Function subtract
|
4 |
|
5 | Subtract two values, `x - y`.
|
6 | For matrices, the function is evaluated element wise.
|
7 |
|
8 |
|
9 | ## Syntax
|
10 |
|
11 | ```js
|
12 | math.subtract(x, y)
|
13 | ```
|
14 |
|
15 | ### Parameters
|
16 |
|
17 | Parameter | Type | Description
|
18 | --------- | ---- | -----------
|
19 | `x` | number | BigNumber | Fraction | Complex | Unit | Array | Matrix | Initial value
|
20 | `y` | number | BigNumber | Fraction | Complex | Unit | Array | Matrix | Value to subtract from `x`
|
21 |
|
22 | ### Returns
|
23 |
|
24 | Type | Description
|
25 | ---- | -----------
|
26 | number | BigNumber | Fraction | Complex | Unit | Array | Matrix | Subtraction of `x` and `y`
|
27 |
|
28 |
|
29 | ## Examples
|
30 |
|
31 | ```js
|
32 | math.subtract(5.3, 2) // returns number 3.3
|
33 |
|
34 | const a = math.complex(2, 3)
|
35 | const b = math.complex(4, 1)
|
36 | math.subtract(a, b) // returns Complex -2 + 2i
|
37 |
|
38 | math.subtract([5, 7, 4], 4) // returns Array [1, 3, 0]
|
39 |
|
40 | const c = math.unit('2.1 km')
|
41 | const d = math.unit('500m')
|
42 | math.subtract(c, d) // returns Unit 1.6 km
|
43 | ```
|
44 |
|
45 |
|
46 | ## See also
|
47 |
|
48 | [add](add.md)
|