How to use the mathjs.divide 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 josdejong / mathjs / examples / fractions.js View on Github external
number: 'Fraction' // Default type of number:
  // 'number' (default), 'BigNumber', or 'Fraction'
})

console.log('basic usage')
printRatio(math.fraction(0.125)) // Fraction, 1/8
printRatio(math.fraction(0.32)) // Fraction, 8/25
printRatio(math.fraction('1/3')) // Fraction, 1/3
printRatio(math.fraction('0.(3)')) // Fraction, 1/3
printRatio(math.fraction(2, 3)) // Fraction, 2/3
printRatio(math.fraction('0.(285714)')) // Fraction, 2/7
console.log()

console.log('round-off errors with numbers')
print(math.add(0.1, 0.2)) // number, 0.30000000000000004
print(math.divide(0.3, 0.2)) // number, 1.4999999999999998
console.log()

console.log('no round-off errors with fractions :)')
print(math.add(math.fraction(0.1), math.fraction(0.2))) // Fraction, 0.3
print(math.divide(math.fraction(0.3), math.fraction(0.2))) // Fraction, 1.5
console.log()

console.log('represent an infinite number of repeating digits')
print(math.fraction('1/3')) // Fraction, 0.(3)
print(math.fraction('2/7')) // Fraction, 0.(285714)
print(math.fraction('23/11')) // Fraction, 2.(09)
console.log()

// one can work conveniently with fractions using the expression parser.
// note though that Fractions are only supported by basic arithmetic functions
console.log('use fractions in the expression parser')
github antoniodeluca / dn2a / assets / networks / alpha.js View on Github external
getOutputError: function() {
        const outputError = // number(
            divide(
                this.dataRepository.neuronLayers[this.dataRepository.neuronLayers.length - 1].reduce(
                    function(totalOutputError, layerNeuron) {
                        return add(
                            totalOutputError,
                            square(layerNeuron.outputError)
                        );
                    },
                    bignumber(0)
                ),
                this.dataRepository.neuronLayers[this.dataRepository.neuronLayers.length - 1].length
            );
        // );
        return outputError;
    },
github uccser / cs-field-guide / csfieldguide / static / interactives / city-trip / js / city-trip.js View on Github external
function calculateRunningTime(cities) {
  var factorialTemp = Mathjs.factorial(cities - 1);
  var numPaths = Mathjs.divide(factorialTemp, 2);
  // The number of seconds is numPaths / 10 but we are now multiplying by 10 to prevent
  // rounding errors so return numPaths. This will be divided by 10 in calculateTimeUnits() when we
  // divide seconds by secondsInUnitOfTime (both are multiplied by 10).

  return Mathjs.bignumber(numPaths);
}
github hashgraph / hedera-mirror-node / hedera-mirror-rest / __acceptancetests__ / acceptancetest_utils.js View on Github external
const nsToSecNs = function(ns) {
  return math
    .divide(math.bignumber(ns), math.bignumber(1e9))
    .toFixed(9)
    .toString();
};
github quantastica / quantum-circuit / lib / quantum-circuit.js View on Github external
var angles = [];
	for(var wire = 0; wire < this.numQubits; wire++) {
		angles.push({ theta: 0, phi: 0 });
	}
	for(var wire = 0; wire < this.numQubits; wire++) {
		var trace = this.partialTrace(wire);

		var alpha = math.round(math.sqrt(trace[0][0]), 14);
		var beta = math.round(math.multiply(trace[1][0], math.sqrt(2)), 14);

		var theta = math.multiply(2, math.acos(alpha));

		var phi = 0;

		if(!(beta.re == 0 && beta.im == 0)) {
			phi = math.multiply(math.complex(0, -1), math.log(math.multiply(beta, math.csc(math.divide(theta, 2))))).re;
		}

		angles[wire].theta = math.round(math.abs(theta), 14);
		angles[wire].phi = math.round(phi, 14);
		angles[wire].thetaDeg = math.round(math.multiply(math.abs(theta), (180 / math.pi)), 7);
		angles[wire].phiDeg = math.round(math.multiply(phi, (180 / math.pi)), 7);
	}

	return angles;
};
github uccser / cs-field-guide / csfieldguide / static / interactives / algorithm-timer / js / algorithm-timer.js View on Github external
'squared': 'n²',
  'cubed': 'n³',
  'fourth-power': 'n<sup>4</sup>',
  'sixth-power': 'n<sup>6</sup>',
  'exponential': '2<sup>n</sup>',
  'factorial': 'n!',
};

const TIME_SCALERS = {
  'nanoseconds': 1000000000,
  'microseconds': 1000000,
  'milliseconds': 1000,
  'seconds': 1,
  'minutes': Mathjs.divide(1, 60),
  'hours': Mathjs.divide(1, 3600),
  'days': Mathjs.divide(1, 86400),
  'years': Mathjs.divide(1, 31557600),
  'centuries': Mathjs.divide(1, 3155760000),
};


$(document).ready(function() {
  var complexity = $('input[name=complexity]:checked').prop('id');
  var resultForm = $('input[name=result-form]:checked').prop('id');
  var n = $('#n-items').val();
  var speed = $('#speed').val();
  var processors = $('#processors').val();
  var timeUnits = $('input[name=time]:checked').prop('id');
  updateData();

  $('input[name=complexity]').click(function() {
    complexity = $('input[name=complexity]:checked').prop('id');
github uccser / cs-field-guide / csfieldguide / static / interactives / algorithm-timer / js / algorithm-timer.js View on Github external
'linear': 'n',
  'squared': 'n²',
  'cubed': 'n³',
  'fourth-power': 'n<sup>4</sup>',
  'sixth-power': 'n<sup>6</sup>',
  'exponential': '2<sup>n</sup>',
  'factorial': 'n!',
};

const TIME_SCALERS = {
  'nanoseconds': 1000000000,
  'microseconds': 1000000,
  'milliseconds': 1000,
  'seconds': 1,
  'minutes': Mathjs.divide(1, 60),
  'hours': Mathjs.divide(1, 3600),
  'days': Mathjs.divide(1, 86400),
  'years': Mathjs.divide(1, 31557600),
  'centuries': Mathjs.divide(1, 3155760000),
};


$(document).ready(function() {
  var complexity = $('input[name=complexity]:checked').prop('id');
  var resultForm = $('input[name=result-form]:checked').prop('id');
  var n = $('#n-items').val();
  var speed = $('#speed').val();
  var processors = $('#processors').val();
  var timeUnits = $('input[name=time]:checked').prop('id');
  updateData();

  $('input[name=complexity]').click(function() {

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 8 days ago

Package Health Score

92 / 100
Full package analysis