mirror of
https://github.com/josdejong/mathjs.git
synced 2025-12-08 19:46:04 +00:00
1.0 KiB
1.0 KiB
Function cos
Calculate the cosine of a value.
For matrices, the function is evaluated element wise.
Syntax
math.cos(x)
Parameters
| Parameter | Type | Description |
|---|---|---|
x |
Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null | Function input |
Returns
| Type | Description |
|---|---|
| Number | BigNumber | Complex | Array | Matrix | Cosine of x |
Examples
math.cos(2); // returns Number -0.4161468365471422
math.cos(math.pi / 4); // returns Number 0.7071067811865475
math.cos(math.unit(180, 'deg')); // returns Number -1
math.cos(math.unit(60, 'deg')); // returns Number 0.5
var angle = 0.2;
math.pow(math.sin(angle), 2) + math.pow(math.cos(angle), 2); // returns Number ~1