How to use the subtract function from mathjs

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

134
135
136
137
138
139
140
141
142
143
const calculateMarketPriceByTotal = (orderSize = 0, orders = []) =>
    orders.reduce(
        ([accumulatedPrice, accumulatedSize], [price = 0, size = 0]) => {
            if (math.larger(orderSize, accumulatedPrice)) {
                let currentTotal = math.multiply(size, price);
                const remainingSize = math.subtract(orderSize, accumulatedPrice);
                if (math.largerEq(remainingSize, currentTotal)) {
                    return [
                        math.sum(accumulatedPrice, currentTotal),
                        math.sum(accumulatedSize, size),
fork icon211
star icon236
watch icon0

+ 3 other calls in file

1
2
3
4
5
6
7
8
9
10

const I = math.complex(0, 1);
const isZero = (x) => (x === 0 || (x.re === 0 && x.im === 0));

const cadd = math.sum;
const csub = math.subtract;
const cdiv = math.divide;
const cmul = math.multiply;
const cmul_i = z => math.multiply(z, I);
const creciprocal = z => math.divide(1, z);
fork icon8
star icon29
watch icon3

+ 3 other calls in file

134
135
136
137
138
139
140
141
142
143
const llCorner = [imageCoordinates.ll[0], imageCoordinates.ll[1], imageCoordinates.ll[2]];//imageCoordinates.ll;
const xyzCam = math.matrix([urCorner, ulCorner, lrCorner, llCorner]);

// Scale the model
// ---------------
const dif = math.subtract(urCorner, ulCorner);
const dist = math.norm(dif);

const maxSize = 100; // max size of the bigest side of the image
let ratio = maxSize / dist;
fork icon3
star icon4
watch icon0

23
24
25
26
27
28
29
30
31
32
getBz() {
  const h=10*this.r2, z=this.z1, omega=maths.dotMultiply(this.f, (2*Math.PI)), wireTurnsDensity=this.wireTurn*this.cur/((this.r2-this.r1)*(this.z2-this.z1));
  const coef=Math.PI*4.0e-7*wireTurnsDensity;
  let q = maths.divide(J1root.slice(0,this.ns+1), h);

  let eqz_ = maths.subtract(maths.exp(maths.dotMultiply(q, -1*(this.z1-z))), maths.exp(maths.dotMultiply(q, -1*(this.z2-z))));
  let eqz = maths.subtract(maths.exp(maths.dotMultiply(q, -1*(this.z1+z))), maths.exp(maths.dotMultiply(q, -1*(this.z2+z))));

  let nu = maths.chain([...Array(1002).keys()])
                .dotMultiply(2)
fork icon2
star icon3
watch icon0

+ 7 other calls in file

18
19
20
21
22
23
24
25
26
27
var results = [data]
for (var i = 1; i < max_iter; i++) {
    var s_points = data["s_points"],
        t_points = data["t_points"]
    var dist_gradient = math.multiply(2, math.subtract(s_points, t_points))
    s_points = math.subtract(s_points, math.multiply(default_learning_rate, dist_gradient))
    data = {"s_points": s_points, "t_points": t_points}
    results.push(data)
    if (callback_draw !== null) {
        callback_draw(data)
fork icon1
star icon1
watch icon7

+ 7 other calls in file

76
77
78
79
80
81
82
83
84
85
const aDig = digitize(/*math.flatten(*/aChannel/*)*/, this.aRange, false);
const bDig = digitize(/*math.flatten(*/bChannel/*)*/, this.bRange, false);

this.imageQuantized = dstack([lDig, aDig, bDig]);

this.imageQuantized = math.subtract(this.imageQuantized, 1);

this.map3d1d = math.zeros(totBins, totBins, totBins).toArray();

// if 0 range this will crash. hack workaround
fork icon0
star icon5
watch icon2

+ 3 other calls in file

52
53
54
55
56
57
58
59
60
 * @param {(Complex|Number)} s - The point in which to evaluate.
 * @returns {(Complex|Number)} The result of the evaluation.
 */
evalzorp: function(a, s) {
    return a
    .map(function(val){ return math.subtract(s, val);} )
    .reduce(function(memo, val){ return math.multiply(memo, val); }, 1);
},

fork icon1
star icon0
watch icon15

42
43
44
45
46
47
48
49
50
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
math.abs(a); // absolute value
fork icon0
star icon3
watch icon0

+ 6 other calls in file

124
125
126
127
128
129
130
131
132
133
// mathjs
//A = math.evaluate("[" + A.toString() + "] kg");
//B = math.evaluate("[" + B.toString() + "] cm");
//C = math.evaluate("[" + C.toString() + "] s");
var mathjsDoMath = performance.timerify(() => {
  return math.subtract(
    math.add(
      math.dotMultiply(4, math.dotDivide(math.dotMultiply(A, math.dotPow(B, 2)), math.dotPow(C, 2))),
      math.dotMultiply(2, math.dotDivide(math.dotMultiply(A, math.dotPow(B, 2)), math.dotPow(C, 2))),
    ),
fork icon0
star icon2
watch icon1

+ 3 other calls in file

169
170
171
172
173
174
175
176
177
178
}
else if (math.equal(valueGE, targetValue)) {
        item.volume = volumeGE;
}
else {
        const d = math.subtract(valueGE, valueLE);
        const p = math.divide(math.subtract(targetValue, valueLE), d);
        // console.log({d, p})
        // console.log(math.multiply(math.subtract(1, p), volumeLE))
        // console.log(math.multiply(p, volumeGE))
fork icon0
star icon9
watch icon3

+ 3 other calls in file

107
108
109
110
111
112
113
114
115
116
getMean(signal) {
  return this.jStatToMathJS(signal.mean());
}

getPeakToPeak(signal) {
  return math.subtract(math.matrix(signal.max()), math.matrix(signal.min()));
}

getKurtosis(signal) {
  return this.jStatToMathJS(signal.kurtosis());
fork icon1
star icon0
watch icon0

500
501
502
503
504
505
506
507
508
509
510
511
	return s.length;
}
lenmax.maximise = true;


function RMSE(x, y) {
	const z = math.subtract(x, y);
	return RMS(z);
}


function RMS(x) {
fork icon1
star icon0
watch icon0

+ 2 other calls in file

49
50
51
52
53
54
55
56
57
58
  this.endpoint2[0] - this.endpoint1[0],
];

const normal = multiply(1 / norm(invSlopeVec), invSlopeVec);

const outVec = subtract(
  ray.direction,
  multiply(2 * dot(ray.direction, normal), normal)
);
return outVec;
fork icon1
star icon0
watch icon0

35
36
37
38
39
40
41
42
43
44
}
let n = b.length;
let d = mathjs.diag(mathjs.diag(A));
let p = triu([...A]);
let o = tril([...A]);
let l = mathjs.subtract(d,o);
let u = mathjs.subtract(d,p);
let T = mathjs.multiply(mathjs.inv(d),mathjs.add(l,u));
let re = mathjs.max(mathjs.abs(mathjs.eigs(T).values));
if(re > 1){
fork icon1
star icon0
watch icon0

+ 3 other calls in file

25
26
27
28
29
30
31
32
33
34
	return;
}
n = b.length;
d = mathjs.diag(mathjs.diag(A));
p = triu(A);
l = mathjs.subtract(A,tril(A));
u = mathjs.subtract(A,triu(A));
T = mathjs.multiply(mathjs.inv(mathjs.subtract(d,l)),u);
re = mathjs.max(mathjs.abs(mathjs.eigs(T).values));
if(re > 1){
fork icon1
star icon0
watch icon0

+ 3 other calls in file

94
95
96
97
98
99
100
101
102
103
}
static add(point_1, point_2) {
    return new Point(math.add(point_1.x, point_2.x), math.add(point_1.y, point_2.y));
}
static subtract(point_1, point_2) {
    return new Point(math.subtract(point_1.x, point_2.x), math.subtract(point_1.y, point_2.y));
}
multiply(value) {
    if (!Decimal.isDecimal(value)) {
        throw "value needs to be of type: math.bignumber";
fork icon1
star icon0
watch icon1

+ 5 other calls in file

60
61
62
63
64
65
66
67
68
69

    return x2;
}

function dTanh(x) {
    return math.subtract(1, math.square(tanh(x)));
}

function sigmoid(x) {
    return math.dotDivide(1, math.add(1, math.exp(math.multiply(-1, x))));
fork icon0
star icon4
watch icon2

10
11
12
13
14
15
16
17
18
19
x_song_norm = math.dotMultiply(x_song, W);
//console.log(x_song_norm)
x_target_norm = math.dotMultiply(x_target, W);
//console.log(x_target_norm)
//Calculate MSE between song and target
e = math.subtract(x_song_norm,x_target_norm);
//console.log(e)
se = math.dotPow(e, 2);
mse = math.mean(se);
return mse;
fork icon0
star icon4
watch icon3

185
186
187
188
189
190
191
192
193
194
var x4o = [];
var X=[];
var maxIter=50;
// Initialize variables
var x = x0;
var r = math.subtract(b, math.multiply(A, x));
var p = r;
var rsold = math.dot(r, r);

// Iterate until convergence or max iterations reached
fork icon0
star icon1
watch icon0

17
18
19
20
21
22
23
24
25
26
if (massSolute != undefined && mwSolute != undefined) { // main formula
    // return massSolute/mwSolute
    return divide(massSolute, mwSolute)
} else if (nSolvent != undefined && nfSolvent != undefined) { // derived formula from nfsolvent
    // return  (nSolvent/nfSolvent) - nSolvent 
    return subtract(divide(nSolvent, nfSolvent), nSolvent)
} else if (nSolvent != undefined && nfSolute != undefined) { // derived formula from nfsolute, parenthesis very improtnat
    // return (nfSolute * nSolvent)/ (1 - nfSolute)
    return divide(multiply(nfSolute, nSolvent), subtract(unit(1), nfSolute))
} else if(molality != undefined && massSolvent != undefined){
fork icon0
star icon1
watch icon0

+ 7 other calls in file