1 | ;
|
2 |
|
3 | var deepMap = require('../../utils/collection/deepMap');
|
4 |
|
5 | function factory(type, config, load, typed) {
|
6 | /**
|
7 | * Calculate the sine of a value.
|
8 | *
|
9 | * For matrices, the function is evaluated element wise.
|
10 | *
|
11 | * Syntax:
|
12 | *
|
13 | * math.sin(x)
|
14 | *
|
15 | * Examples:
|
16 | *
|
17 | * math.sin(2) // returns number 0.9092974268256813
|
18 | * math.sin(math.pi / 4) // returns number 0.7071067811865475
|
19 | * math.sin(math.unit(90, 'deg')) // returns number 1
|
20 | * math.sin(math.unit(30, 'deg')) // returns number 0.5
|
21 | *
|
22 | * const angle = 0.2
|
23 | * math.pow(math.sin(angle), 2) + math.pow(math.cos(angle), 2) // returns number ~1
|
24 | *
|
25 | * See also:
|
26 | *
|
27 | * cos, tan
|
28 | *
|
29 | * @param {number | BigNumber | Complex | Unit | Array | Matrix} x Function input
|
30 | * @return {number | BigNumber | Complex | Array | Matrix} Sine of x
|
31 | */
|
32 | var sin = typed('sin', {
|
33 | 'number': Math.sin,
|
34 |
|
35 | 'Complex': function Complex(x) {
|
36 | return x.sin();
|
37 | },
|
38 |
|
39 | 'BigNumber': function BigNumber(x) {
|
40 | return x.sin();
|
41 | },
|
42 |
|
43 | 'Unit': function Unit(x) {
|
44 | if (!x.hasBase(type.Unit.BASE_UNITS.ANGLE)) {
|
45 | throw new TypeError('Unit in function sin is no angle');
|
46 | }
|
47 | return sin(x.value);
|
48 | },
|
49 |
|
50 | 'Array | Matrix': function ArrayMatrix(x) {
|
51 | // deep map collection, skip zeros since sin(0) = 0
|
52 | return deepMap(x, sin, true);
|
53 | }
|
54 | });
|
55 |
|
56 | sin.toTex = { 1: '\\sin\\left(${args[0]}\\right)' };
|
57 |
|
58 | return sin;
|
59 | }
|
60 |
|
61 | exports.name = 'sin';
|
62 | exports.factory = factory; |
\ | No newline at end of file |