How to use the mathjs.abs 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 birnbaum / rfvis / src / _compute_coordinates.js View on Github external
}
        for (let t = 0; t < treeStrengths.length; t++) {
            // skip current tree
            if (t === i) continue;

            // transform correlation into distance
            const distance = (1 - forest.correlationMatrix[i][t]) * rmax + rmin;

            // produce voting image
            const r = math.sqrt(
                math.add(
                    math.dotPow(math.subtract(X, position.valueOf()[0][i]), 2),
                    math.dotPow(math.subtract(Y, position.valueOf()[1][i]), 2)
                )
            );
            const votingImage = math.number(math.smaller(math.abs(math.subtract(r, distance)), width));

            // Pad voting image with zeros to 120x120, so the convolution will return a 100x100 result
            const paddedVotingImage = math.subset(math.zeros(N + 20, N + 20), math.index(math.range(10, N + 10), math.range(10, N + 10)), votingImage);
            const tmp = math.matrix(nj.array(paddedVotingImage.valueOf()).convolve(GAUSSIAN_2D).tolist());

            // vote
            const oldVotingImage = math.subset(votingMatrices, math.index(math.range(0, N), math.range(0, N), t));
            const newVotingImage = math.add(oldVotingImage, math.reshape(tmp, [N, N, 1]));
            votingMatrices = math.subset(votingMatrices, math.index(math.range(0, N), math.range(0, N), t), newVotingImage)
        }

        // "delete" current tree from list
        treeStrengths[i] = 0;
    }
    console.timeEnd('Computing forest map');
github qt / qtbase / util / gradientgen / gradientgen.js View on Github external
args[args.length - 1].push(arg.value);
              return args;
          }, [[]]);

          let angle = valueParser.unit(args[0][0]);
          if (angle.unit !== 'deg')
            return;

          angle = parseInt(angle.number);
          if (angle < 0)
            angle += 360;

          // Angle is in degrees, but we need radians
          const radians = angle * math.pi / 180;

          const gradientLine = (math.abs(math.sin(radians)) + math.abs(math.cos(radians)));
          const cathetus = fn => math.round(fn(radians - math.pi / 2) * gradientLine / 2, 10);

          const x = cathetus(math.cos);
          const y = cathetus(math.sin);

          const start = { x: 0.5 - x, y: 0.5 - y };
          const end = { x: 0.5 + x, y: 0.5 + y };

          let stops = []

          let lastPosition = 0;
          args.slice(1).forEach((arg, index) => {
            let [color, position = !index ? '0%' : '100%'] = arg;
            position = parseInt(position) / 100;
            if (position < lastPosition)
              position = lastPosition;
github firepick1 / firenodejs / js / lib / LPPCurve.js View on Github external
var maxp1 = 0;
        var maxp2 = 0;
        var maxp3 = 0;
        for (var i = 0; i < pts.length; i++) {
            var pt = pts[i];
            logger.debug(i,
                "\t", pt.p1 - ptPrev.p1,
                "\t", pt.p1,
                "\t", pt.p2,
                "\t", pt.p3,
                "\t", pt.x,
                "\t", pt.y,
                "\t", pt.z
            );
            maxp1 = math.max(maxp1, math.abs(pt.p1 - ptPrev.p1));
            maxp2 = math.max(maxp2, math.abs(pt.p2 - ptPrev.p2));
            maxp3 = math.max(maxp3, math.abs(pt.p3 - ptPrev.p3));
            ptPrev = pt;
            if (pt.z > lpp.zHigh - lpp.zVertical) {
                math.abs(pt.x).should.below(0.1);
                math.abs(pt.y).should.below(0.1);
            }
            if (z + lpp.zVertical > pt.z) {
                math.abs(x - pt.x).should.below(0.1);
                math.abs(y - pt.y).should.below(0.1);
            }
        }
        var ds = new DataSeries();
        var diff = ds.diff(pts, "z");
        diff.max.should.below(0); // z is monotonic decreasing
        diff = ds.diff(pts, "y");
        diff.min.should.above(-eMicrostep); // y is monotonic increasing within microstep tolerance
github firepick1 / firenodejs / js / lib / LPPCurve.js View on Github external
var d1Prev;
        var d2Prev;
        var d3Prev;
        var smooth = false;
        var i = 0;
        while (i++ < maxIterations) {
            ds.blur(pts, "p1");
            ds.blur(pts, "p2");
            ds.blur(pts, "p3");
            d1 = ds.diff(pts, "p1");
            if (d1Prev != null) {
                if (math.abs(d1Prev.max - d1.max) < that.deltaSmoothness) {
                    that.logger.debug("deltaSmoothness p1 converged:", i);
                    d2 = ds.diff(pts, "p2");
                    if (d2Prev != null) {
                        if (math.abs(d2Prev.max - d2.max) < that.deltaSmoothness) {
                            that.logger.debug("deltaSmoothness p2 converged:", i);
                            d3 = ds.diff(pts, "p3");
                            if (d3Prev != null) {
                                if (math.abs(d3Prev.max - d3.max) < that.deltaSmoothness) {
                                    that.logger.debug("deltaSmoothness p3 converged:", i);
                                    smooth = true;
                                    break;
                                }
                            }
                            d3Prev = d3;
                        }
                    }
                    d2Prev = d2;
                }
            }
            d1Prev = d1;
github ElliotPenson / fractal.parts / frontend / src / graphics / geometry.js View on Github external
export function distanceToLine(point, lineA, lineB) {
  const numerator =
    (lineB.y - lineA.y) * point.x -
    (lineB.x - lineA.x) * point.y +
    lineB.x * lineA.y -
    lineB.y * lineA.x;
  const denominator = distance(lineA, lineB);
  return abs(numerator) / denominator;
}
github ElliotPenson / fractal.parts / frontend / src / graphics / geometry.js View on Github external
function findTriangleArea(cornerA, cornerB, cornerC) {
  const determinant =
    cornerA.x * cornerB.y +
    cornerB.x * cornerC.y +
    cornerC.x * cornerA.y -
    cornerB.x * cornerA.y -
    cornerC.x * cornerB.y -
    cornerA.x * cornerC.y;
  return 0.5 * abs(determinant);
}
github firepick1 / firenodejs / js / lib / LPPCurve.js View on Github external
function assertGentle(pts, d0, d1, d2) {
        var N = pts.length - 1;
        var d = [
            d0 || 15,
            d1 || 35,
            d2 || 60,
        ]
        for (var i = 0; i < 3; i++) {
            for (var j = 1; j <= 3; j++) {
                var key = "p" + j;
                math.abs(pts[i][key] - pts[i + 1][key]).should.below(d[i]);
                math.abs(pts[N - i][key] - pts[N - i - 1][key]).should.below(d[i]);
            }
        }
    }
github quantastica / quantum-circuit / lib / quantum-circuit.js View on Github external
var formatComplex2 = function(re, im) {
	var re = math.round(re, 7);
	var im = math.round(im, 7);
	return (re >= 0 ? " " : "-") + math.abs(re).toFixed(8) + (im >= 0 ? "+" : "-") + math.abs(im).toFixed(8) + "i";
};

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