How to use the mathjs.multiply 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 / units.js View on Github external
// load math.js (using node.js)
const math = require('mathjs')

// units can be created by providing a value and unit name, or by providing
// a string with a valued unit.
console.log('create units')
const a = math.unit(45, 'cm')
const b = math.unit('0.1m')
print(a) // 45 cm
print(b) // 0.1 m
console.log()

// units can be added, subtracted, and multiplied or divided by numbers and by other units
console.log('perform operations')
print(math.add(a, b)) // 55 cm
print(math.multiply(b, 2)) // 0.2 m
print(math.divide(math.unit('1 m'), math.unit('1 s'))) // 1 m / s
print(math.pow(math.unit('12 in'), 3)) // 1728 in^3
console.log()

// units can be converted to a specific type, or to a number
console.log('convert to another type or to a number')
print(b.to('cm')) // 10 cm  Alternatively: math.to(b, 'cm')
print(math.to(b, 'inch')) // 3.9370078740157 inch
print(b.toNumber('cm')) // 10
print(math.number(b, 'cm')) // 10
console.log()

// the expression parser supports units too
console.log('parse expressions')
print(math.eval('2 inch to cm')) // 5.08 cm
print(math.eval('cos(45 deg)')) // 0.70710678118655
github SpatialTranscriptomicsResearch / st_spot_detector / client / src / app / viewer.directive.js View on Github external
const context = canvas.getContext('2d');

                        if (layer.get('visible') === false) {
                            clear(context);
                            return;
                        }

                        const adjustments = layer.adjustments;

                        $(layer.canvas).css('opacity', _.reduce(
                            _.filter(adjustments, ([x]) => x === 'opacity'),
                            (a, [, x]) => a * x,
                            1.0,
                        ));

                        const tmat = math.multiply(camera.getTransform(), layer.tmat);

                        // Compute difference to previous transformation matrix, set the
                        // transformation matrix to the difference, and redraw the canvas at (0, 0),
                        // thus transforming the canvas according to the difference (this serves as
                        // a 'quick refresh' before the requests to the renderingClient complete).
                        // const tmatOld = transformToMathjs(context.currentTransform);
                        // TODO: proper polyfill of CanvasRenderingContext2d.currentTransform
                        let tmatOld;
                        if (layer.currentTransform !== undefined) {
                            tmatOld = layer.currentTransform;
                        } else {
                            tmatOld = math.eye(3);
                        }
                        layer.currentTransform = tmat;
                        const tmatDiff = math.multiply(tmat, math.inv(tmatOld));
github quantastica / quantum-circuit / lib / quantum-circuit.js View on Github external
var map = bitMaps[itemIndex];

			var a1 = 0;
			for(var i = 0; i < map.length; i++) {
				if(a3 & map[i].and) {
					a1 |= map[i].or;
				}
			}

			var item = combineList[itemIndex];
			var s1 = item.circuit.state[a1];
			if(s1) {
				if(s3 == null) {
					s3 = s1;
				} else {
					s3 = math.multiply(s1, s3);
				}
			} else {
				s3 = math.complex(0, 0);
			}
		}

		if(s3 && (s3.re || s3.im)) {
			newState[a3] = s3;
			newStateBits |= a3;
		}
	}

	this.resetState();
	// expand circuit if needed
	if(this.numQubits < totalQubits) {
		this.numQubits = totalQubits;
github javascript-machine-learning / linear-algebra-matrix / index.js View on Github external
console.log('const h3 = x => -150 + 0.4 * x;');
console.log('\n');

const houseSizeMatrix = math.matrix([
  [1, 2104],
  [1, 1416],
  [1, 1534],
  [1, 852],
]);

const hypothesesMatrix = math.matrix([
  [-40, 200, -150],
  [0.25, 0.1, 0.4],
]);

const competingResults = math.multiply(houseSizeMatrix, hypothesesMatrix);

console.log('Column: Result for each Hypothesis');
console.log('Row: Result for each House Size');
console.log(competingResults.valueOf());
console.log('\n');
github quantastica / quantum-circuit / lib / quantum-circuit.js View on Github external
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] ],
		[ trace[2], trace[3] ]
	];
};
github projectstorm / react-diagrams / packages / geometry / src / Point.ts View on Github external
transform(matrix: Matrix) {
		let final: Matrix = mathjs.multiply(matrix, this.asMatrix()) as Matrix;
		this.x = final.get([0, 0]);
		this.y = final.get([1, 0]);
	}
github antoniodeluca / dn2a / assets / networks / alpha.js View on Github external
function(
                                synapse,
                                synapseIndex,
                                synapses
                            ) {
                                synapse.previousWeightChange = synapse.weightChange;
                                synapse.weightChange = add(
                                    multiply(
                                        bignumber(learningRate),
                                        multiply(
                                            layerNeuron.delta,
                                            synapse.incomingConnection.output
                                        )
                                    ),
                                    multiply(
                                        bignumber(momentumRate),
                                        synapse.previousWeightChange
                                    )
                                );
                                synapse.previousWeight = synapse.weight;
                                synapse.weight = add(
                                    synapse.weight,
                                    synapse.weightChange
                                );
                            }
                        );

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 5 hours ago

Package Health Score

89 / 100
Full package analysis