mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-18 14:59:29 +00:00
984 B
984 B
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 | Boolean | Complex | Unit | Array | Matrix | Function input |
Returns
| Type | Description |
|---|---|
| Number | 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