How to use the sin function from mathjs

Find comprehensive JavaScript mathjs.sin code examples handpicked from public code repositorys.

6
7
8
9
10
11
12
13
14
15
console.log(math.cot(2));   
console.log(1 / math.tan(2));  
console.log(math.sec(2));  
console.log(1 / math.cos(2));   
console.log(math.csc(2));   
console.log(1 / math.sin(2));   
console.log(math.asin(0.5));  
console.log(math.atan(0.5));  
console.log(math.atan2(2, 2) / math.pi);   
console.log(math.acos(0.5));  
fork icon19
star icon29
watch icon6

+ 5 other calls in file

6
7
8
9
10
11
12
13
14
15
const csub = math.subtract;
const cdiv = math.divide;
const cmul = math.multiply;
const cmul_i = z => math.multiply(z, I);
const creciprocal = z => math.divide(1, z);
const csin = math.sin;
const cexp = math.exp;
const clog = math.log;
const csqrt = math.sqrt;
const cpow = math.pow;
fork icon8
star icon29
watch icon3

+ 11 other calls in file

48
49
50
51
52
53
54
55
56
57

sphereCarthesianCoordinates() {
    const sphereCoord = this.sphereAngleCoordinates();

    const ax = math.sin(sphereCoord.teta) * math.cos(sphereCoord.phi);
    const ay = math.sin(sphereCoord.teta) * math.sin(sphereCoord.phi);
    const az = math.cos(sphereCoord.teta);

    return {
        x: ax,
fork icon2
star icon4
watch icon3

+ 3 other calls in file

37
38
39
40
41
42
43
44
45
46
    height,
    depth,
    orientation,
    {
        x: originX + (width / 2) * cos((orientation / 180) * Math.PI),
        y: originY + (width / 2) * sin((orientation / 180) * Math.PI)
    },
    reality,
    debug
);
fork icon2
star icon1
watch icon2

+ 11 other calls in file

85
86
87
88
89
90
91
92
93
94
// trig
// sin, cos, tan
// sec, csc, cot
// asin, acos, atan (...)
// sinh, cosh, tanh (...)
math.sin(math.pi / 2);

// check
math.isInteger(a)
math.isNaN(a)
fork icon0
star icon3
watch icon1

+ 2 other calls in file

726
727
728
729
730
731
732
733
734
735
this.vx.rounded.value = SigFig(this.vx.rounded.value, this.sf)
this.equationInLatex.push(`v_{x} = v_{i}cos(\\theta) \\implies ${this.vi.toString()} \\cdot cos(${this.angle.toString()}) = ${this.vx.rounded.toString()}`)
find += "Horizontal Velocity (vx), "
answer += ` - Horizontal Velocity (vx): \`${this.vx.actual.toString()}\` = \`${this.vx.rounded.toString()}\`\n`

this.vy.actual = multiply(this.vi, sin(this.angle))
this.vy.rounded = clone(this.vy.actual);
this.vy.rounded.value = SigFig(this.vy.rounded.value, this.sf)
this.equationInLatex.push(`v_{y} = v_{i}sin(\\theta) \\implies ${this.vi.toString()} \\cdot sin(${this.angle.toString()}) = ${this.vy.rounded.toString()}`)
find += "Vertical Velocity (vy), "
fork icon0
star icon1
watch icon0

145
146
147
148
149
150
151
152
153
154
  }
}

buildFunctionsArray(){
  let sin = function(x){
    return Mathjs.sin(x);
  }
  let cos = function(x){
    return Mathjs.cos(x);
  }
fork icon0
star icon1
watch icon1

+ 7 other calls in file

51
52
53
54
55
56
57
58
59
60
  ray.notInAir = true;
  const theta2 = asin(sin(theta1) / this.n);
  if (ray.direction[0] < 0) {
    return [-cos(theta2), sin(theta2)];
  }
  return [cos(theta2), sin(theta2)];
} else {
  ray.notInAir = false;
  const theta2 = asin(this.n * sin(theta1));
  return [cos(theta2), sin(theta2)];
fork icon1
star icon0
watch icon0

+ 11 other calls in file

119
120
121
122
123
124
125
126
127
128
129
130


function epicycloid(r0, k, theta) {
  const kp1 = k + 1;
  return [
    r0 * kp1 * math.cos(theta) - r0 * math.cos(kp1 * theta),
    r0 * kp1 * math.sin(theta) - r0 * math.sin(kp1 * theta),
  ];
}


function subtractAngles(a0, a1) {
fork icon0
star icon0
watch icon0

+ 6 other calls in file

70
71
72
73
74
75
76
77
78
79

```js
var math = require('mathjs');

// use methods and types available in the math object
var a = math.sin(math.pi / 4);  // 0.7071067811865476
var b = math.pow(a, 2);         // 0.5

var c = math.complex(3, -4);    // 3 - 4i
math.sqrt(c);                   // 2 - i
fork icon0
star icon0
watch icon2

+ 15 other calls in file