How to use the mathjs.pow function in mathjs

To help you get started, we’ve selected a few mathjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lin-xin / calculator / static / script / index.js View on Github external
clickSpecial(type, event) {
        const _this = this,
            res = document.querySelector('.result-text');
        _this.flag = true;
        _this.removeActive();
        switch (type) {
            case '1': // x 的平方
                res.innerHTML = result = math.format(math.pow(result, 2), {
                    precision: 16
                });
                _this.register.ope = type;
                _this.isEqual = true;

                break;
            case '2': // x 的立方
                res.innerHTML = result = math.format(math.pow(result, 3), {
                    precision: 16
                });
                _this.register.ope = type;
                _this.isEqual = true;
                break;
            case '3': // x 的 y 次幂
                _this.events = event;
                if (!event.classList.contains('active')) {
github KyberNetwork / smart-contracts / test / helper.js View on Github external
module.exports.exp = function(num1,num2) {
    const num1Math = Math.bignumber(new BigNumber(num1).toString(10));
    const num2Math = Math.bignumber(new BigNumber(num2).toString(10));

    const result = Math.pow(num1Math,num2Math);

    return new BigNumber(result.toString());
};
github Qiskit / qiskit-js / packages / qiskit-sim / lib / Circuit.js View on Github external
stateToString() {
    const numAmplitudes = this.numAmplitudes();

    if (!this.state || this.state.length < numAmplitudes) {
      throw new Error(
        'Circuit is not initialized. Please call init() or run() method',
      );
    }

    let s = '';
    for (let i = 0; i < numAmplitudes; i += 1) {
      if (i) {
        s += '\n';
      }

      const m = math.round(math.pow(math.abs(this.state[i]), 2) * 100, 2);
      let bin = i.toString(2);
      while (bin.length < this.nQubits) {
        bin = `0${bin}`;
      }
      s += `${utils.formatComplex(this.state[i])}|${bin}>${m}%`;
    }

    return s;
  }
github quantastica / quantum-circuit / lib / quantum-circuit.js View on Github external
function insertBit(input, pos, bit) {
		var out = input << 1;
		var m = (2 << pos) - 1;
		var posBit = 1 << pos;
		var out = (out ^ ((out ^ input) & m)) | posBit; 
		if(!bit) {
			out = out ^ posBit;
		}
		return out;
	}

	var trace = [];

	var unusedCount = this.numQubits - 1;
	var unusedLen = math.pow(2, unusedCount);
	var qpos = (this.numQubits - 1) - qubit;
	for(var el = 0; el < 4; el++) {
		trace.push(math.complex(0, 0));
		var base = unusedLen;
		while(base--) {
			var col = insertBit(base, qpos, el & 1 ? 1 : 0);
			var row = insertBit(base, qpos, el & 2 ? 1 : 0);
			var rowVal = this.state[row];
			var colVal = this.state[col];
			if(rowVal && colVal) {
				trace[el] = math.add(trace[el], math.multiply(rowVal, math.complex(colVal.re, colVal.im * -1.0)));
			}
		}
	}
	return [
		[ trace[0], trace[1] ],
github Qiskit / qiskit-js / packages / qiskit-sim / lib / Circuit.js View on Github external
load(obj) {
    this.nQubits = obj.nQubits || 1;
    this.amplitudes = math.pow(2, this.nQubits);
    this.clear();
    this.gates = obj.gates;
    this.customGates = obj.customGates;
    this.state = obj.state;
  }
github yosriady / node-bayes / index.js View on Github external
function numericProbability(value, mean, std) {
  return (1 / (std * math.sqrt(2 * math.pi))) *
                            math.pow(math.e,
                                     (-(math.pow(value - mean, 2)) /
                                      (2 * math.pow(std,2)))
                                    );
}
github quantastica / quantum-circuit / lib / quantum-circuit.js View on Github external
QuantumCircuit.prototype.getCregValue = function(creg) {
	if(!this.cregs[creg]) {
		throw "Error: \"getCregBit\": unknown register \"" + creg + "\".";
	}

	var len = this.cregs[creg].length;
	var value = 0;
	for(var i = 0; i < len; i++) {
		if(this.cregs[creg][i]) {
			value += math.pow(2, i);
		}
	}
	return value;
};
github Qiskit / qiskit-js / packages / qiskit-sim / lib / gateSingle.js View on Github external
module.exports = (gate, qubit, nQubits, state) => {
  const temp1 = math
    .chain(math.eye(math.pow(2, nQubits - qubit - 1)))
    .multiply(complex)
    .done();
  const temp2 = math
    .chain(math.eye(math.pow(2, qubit)))
    .multiply(complex)
    .done();
  const enlargeOpt = math.kron(temp1, math.kron(gate, temp2));

  return math.multiply(enlargeOpt, state);
};
github yosriady / node-bayes / index.js View on Github external
function numericProbability(value, mean, std) {
  return (1 / (std * math.sqrt(2 * math.pi))) *
                            math.pow(math.e,
                                     (-(math.pow(value - mean, 2)) /
                                      (2 * math.pow(std,2)))
                                    );
}

mathjs

Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with dif

Apache-2.0
Latest version published 1 month ago

Package Health Score

91 / 100
Full package analysis