How to use the pow function from mathjs

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

28
29
30
31
32
33
34
35
36
37
if (number === 0 || number === Infinity || isNaN(number)) {
    return 0;
} else if (decimals > 0) {
    const multipliedNumber = math.multiply(
        math.fraction(number),
        math.pow(10, decimals)
    );
    const dividedNumber = math.divide(
        math.floor(multipliedNumber),
        math.pow(10, decimals)
fork icon211
star icon236
watch icon0

+ 3 other calls in file

13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
	return circ.circuitMatrix();
};


QuantumCircuit.prototype.eulerAnglesZYZ = function(inputMatrix) {
	var eulerAngles = {theta: null, phi: null, lambda: null, phase: null};
	var coeff = math.pow(math.det(inputMatrix), -0.5);
	eulerAngles.phase = -1 * math.complex(coeff).toPolar().phi;
	var su_mat = math.multiply(coeff, inputMatrix);
	eulerAngles.theta = 2 * math.atan2(math.abs(su_mat[1][0]), math.abs(su_mat[0][0]));
	var phiplambda = 2 * math.complex(su_mat[1][1]).toPolar().phi;
fork icon43
star icon207
watch icon14

+ 2369 other calls in file

10
11
12
13
14
15
16
17
18
19
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;
const csquare = z => cmul(z, z);
const ccis = z => cexp(cmul_i(z));

const gamma_right = math.gamma;
fork icon8
star icon29
watch icon3

+ 3 other calls in file

37
38
39
40
41
42
43
44
45
46
exports.inflate = function inflate(A, factor) {
  return this.normalizeColumns(math.dotPow(A, factor));
};

exports.expand = function expand(A, factor) {
  return math.pow(A, factor);
};

exports.addDiagonal = function addDiagonal(A, value) {
  const diag = math.eye(A.size());
fork icon2
star icon6
watch icon2

79
80
81
82
83
84
85
86
87
88
```js
let math = require('mathjs');

let base = 2,
exp = 3,
n = math.pow(base,exp); // 8
 
console.log( math.log(n,base) ); // 3
console.log( math.log(n,base) === exp ) // true
```
fork icon0
star icon5
watch icon1

40
41
42
43
44
45
46
47
48
49
math.exp(8) // exponent (e ** x)
math.log(a) // ln
math.log(a, 2) // log base 2
math.mod(a, b) // modulus (remainder)
math.multiply(a, b) // multiply
math.pow(a, b) // a ** b
math.sqrt(a) // square root
math.subtract(a, b) // subtract

// abs
fork icon0
star icon3
watch icon1

+ 2 other calls in file

132
133
134
135
136
137
138
139
140
141
142
  }
  return commitments;
}


function shareVerfication(i, g, coefficients, P) {
  let verification = math.pow(g, coefficients[0]);
  for (let j = 1; j < coefficients.length; j++) {
    verification =
      (verification * Math.pow(Math.pow(share, coefficients[j])),
      Math.pow(i, j));
fork icon0
star icon1
watch icon0

41
42
43
44
45
46
47
48
49
50
 * @param {Boolean|Complex} [inclusive=true] - Wheter or not the endpoint exponent should be included.
 * @return {Array<(Number|Complex)>} The array of equidistant points in logspace.
 */
logspace: function(start, end, num, inclusive, base) {
    base = base || 10;
    return this.linspace(start, end, num, inclusive).map(function(exponent) { return math.pow(base, exponent); });
},

/**
 * Evaluates a list of (Complex) numbers in s as if the list containes zeros/poles.
fork icon1
star icon0
watch icon15

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 icon0

+ 15 other calls in file

81
82
83
84
85
86
87
88
89
90
 * @return {[type]}       [description]
 */
function gamma_correction(value) {
  let result = value;
  if (value > 0.04045) {
    result = math.pow(((value + 0.055) / (1.0 + 0.055)), 2.4);
  } else {
    result = value / 12.92;
  }
  return result;
fork icon0
star icon0
watch icon9

81
82
83
84
85
86
87
88
89
90
  let [ dividend, divisor ] = biggify(args)
  return math.divide(dividend, divisor)
},
pow(...args) {
  let [ base, exp ] = biggify(args)
  return math.pow(base, exp)
},
neg(num) {
  num = math.bignumber(num)
  return math.unaryMinus(num)
fork icon0
star icon0
watch icon1

176
177
178
179
180
181
182
183
184
185

// calculate error
errorVector = math.squeeze(outputError);
var error = 0.0;
if (typeof errorVector === 'number')
    error = 0.5 * math.pow(errorVector, 2);
else
    error = 0.5 * math.dot(errorVector, errorVector);

return error;
fork icon0
star icon0
watch icon0

27
28
29
30
31
32
33
34
35
36
37
/**
 * derivative of sigmoid function
 * @param {number} y value
 */
var dsigmoid = (y) => (sigmoid(y) * (1 - sigmoid(y)));//(1.0 - math.pow(y, 2));
// var dsigmoid = (y) => (1.0 - math.pow(y, 2));


/**
 * Neural Network class
 * @param {number} inputNum node count of input layer
fork icon0
star icon0
watch icon0

+ 2 other calls in file

26
27
28
29
30
31
32
33
34
35
36
// var sigmoid = (x) => math.tanh(x);
/**
 * derivative of sigmoid function
 * @param {number} y value
 */
var dsigmoid = (y) => ((y > 0.0)? 1 : 0.01);//(1.0 - math.pow(y, 2));
// var dsigmoid = (y) => (1.0 - math.pow(y, 2));


/**
 * Neural Network class
fork icon0
star icon0
watch icon0

+ 2 other calls in file

2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
lat2 = lat2 * mathjs.pi / 180;

// Haversine formula
let dlon = lon2 - lon1;
let dlat = lat2 - lat1;
let a = mathjs.pow(mathjs.sin(dlat / 2), 2)
         + mathjs.cos(lat1) * mathjs.cos(lat2)
         * mathjs.pow(mathjs.sin(dlon / 2), 2);
       
let c = 2 * mathjs.asin(mathjs.sqrt(a));
fork icon0
star icon0
watch icon0

+ 5 other calls in file

151
152
153
154
155
156
157
158
159
160
}

// Generate the index
let index = 0;
for (let k = 0, l = 9; k < numStages; k++, l--) {
  index += math.pow(nl, l) * math.floor(nl * ps[k]);
}

// Interpolate
// interpolated index = Floor[3.464 x 10^9 * index/(nl^10)
fork icon0
star icon0
watch icon0

+ 3 other calls in file