How to use the square function from mathjs

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

13
14
15
16
17
18
19
20
21
22

const outliers = []
const filteredPoints = points.filter(pt => {
  if (
    square(pt[0] - medianPoint[0]) / square(sigma * madValue[0]) +
    square(pt[1] - medianPoint[1]) / square(sigma * madValue[1]) < 1
  ) {
    return true
  } else {
    outliers.push(pt)
fork icon0
star icon3
watch icon0

39
40
41
42
43
44
45
46
47
48
if (this.height.actual == undefined && this.time.actual == undefined) {
    this.finalVelocity.actual = unit(this.finalVelocity.actual);
    this.finalVelocity.rounded = clone(this.finalVelocity.actual);
    this.finalVelocity.rounded.value = SigFig(this.finalVelocity.rounded.value, this.roundToSigFig) 
    // First find the height using the formula d = vf^2 - vi^2 / 2g 
    this.height.actual = divide(subtract(square(this.finalVelocity.actual), square(this.initialVelocity.actual)), multiply(2, gravity));
    this.height.rounded = clone(this.height.actual);
    this.height.rounded.value = SigFig(this.height.rounded.value, this.roundToSigFig) 
    this.equationInLatex.push(`d = \\frac{{v_{f}}^{2} - {v_{i}}^{2}}{2g} \\implies \\frac{(${this.finalVelocity.actual.toString()})^{2} - (${this.initialVelocity.actual.toString()})^{2}}{2(${gravity.toString()})} = ${this.height.rounded.toString()}`)
    // Find the time use the formula t = vf - vi / g
fork icon0
star icon1
watch icon0

+ 4 other calls in file

9
10
11
12
13
14
15
16
17
18
// mediana (número entre o maior e o menor -> 2)
console.log('mediana:', math.median([2, 1, 3]));
// produto (multiplicação)
console.log('produto:', math.prod([2, 1, 3]));
// quadrado (eleva cada elemento)
console.log('quadrado:', math.square([2, 1, 3]));
// cubo (eleva cada elemento)
console.log('cubo:', math.cube([2, 1, 3]));
// absoluto (valor positivo)
console.log('absoluto:', math.abs([-2, 1.5, -3]));
fork icon0
star icon0
watch icon0

+ 2 other calls in file