55 lines
1.2 KiB
Markdown
55 lines
1.2 KiB
Markdown
|
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
|
||
|
|
||
|
# Function subtract
|
||
|
|
||
|
Subtract two values, `x - y`.
|
||
|
For matrices, the function is evaluated element wise.
|
||
|
|
||
|
|
||
|
## Syntax
|
||
|
|
||
|
```js
|
||
|
math.subtract(x, y)
|
||
|
```
|
||
|
|
||
|
### Parameters
|
||
|
|
||
|
Parameter | Type | Description
|
||
|
--------- | ---- | -----------
|
||
|
`x` | number | BigNumber | Fraction | Complex | Unit | Array | Matrix | Initial value
|
||
|
`y` | number | BigNumber | Fraction | Complex | Unit | Array | Matrix | Value to subtract from `x`
|
||
|
|
||
|
### Returns
|
||
|
|
||
|
Type | Description
|
||
|
---- | -----------
|
||
|
number | BigNumber | Fraction | Complex | Unit | Array | Matrix | Subtraction of `x` and `y`
|
||
|
|
||
|
|
||
|
### Throws
|
||
|
|
||
|
Type | Description
|
||
|
---- | -----------
|
||
|
|
||
|
|
||
|
## Examples
|
||
|
|
||
|
```js
|
||
|
math.subtract(5.3, 2) // returns number 3.3
|
||
|
|
||
|
const a = math.complex(2, 3)
|
||
|
const b = math.complex(4, 1)
|
||
|
math.subtract(a, b) // returns Complex -2 + 2i
|
||
|
|
||
|
math.subtract([5, 7, 4], 4) // returns Array [1, 3, 0]
|
||
|
|
||
|
const c = math.unit('2.1 km')
|
||
|
const d = math.unit('500m')
|
||
|
math.subtract(c, d) // returns Unit 1.6 km
|
||
|
```
|
||
|
|
||
|
|
||
|
## See also
|
||
|
|
||
|
[add](add.md)
|