# 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.

birnbaum / rfvis / src / _compute_coordinates.js View on Github
}
for (let t = 0; t &lt; 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.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);

// 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');
qt / qtbase / util / gradientgen / gradientgen.js View on Github
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 &lt; 0)
angle += 360;

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

const cathetus = fn =&gt; 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) =&gt; {
let [color, position = !index ? '0%' : '100%'] = arg;
position = parseInt(position) / 100;
if (position &lt; lastPosition)
position = lastPosition;
firepick1 / firenodejs / js / lib / LPPCurve.js View on Github
var maxp1 = 0;
var maxp2 = 0;
var maxp3 = 0;
for (var i = 0; i &lt; 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 &gt; lpp.zHigh - lpp.zVertical) {
math.abs(pt.x).should.below(0.1);
math.abs(pt.y).should.below(0.1);
}
if (z + lpp.zVertical &gt; 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
firepick1 / firenodejs / js / lib / LPPCurve.js View on Github
var d1Prev;
var d2Prev;
var d3Prev;
var smooth = false;
var i = 0;
while (i++ &lt; 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) &lt; that.deltaSmoothness) {
that.logger.debug("deltaSmoothness p1 converged:", i);
d2 = ds.diff(pts, "p2");
if (d2Prev != null) {
if (math.abs(d2Prev.max - d2.max) &lt; that.deltaSmoothness) {
that.logger.debug("deltaSmoothness p2 converged:", i);
d3 = ds.diff(pts, "p3");
if (d3Prev != null) {
if (math.abs(d3Prev.max - d3.max) &lt; that.deltaSmoothness) {
that.logger.debug("deltaSmoothness p3 converged:", i);
smooth = true;
break;
}
}
d3Prev = d3;
}
}
d2Prev = d2;
}
}
d1Prev = d1;
ElliotPenson / fractal.parts / frontend / src / graphics / geometry.js View on Github
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;
}
ElliotPenson / fractal.parts / frontend / src / graphics / geometry.js View on Github
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);
}
firepick1 / firenodejs / js / lib / LPPCurve.js View on Github
function assertGentle(pts, d0, d1, d2) {
var N = pts.length - 1;
var d = [
d0 || 15,
d1 || 35,
d2 || 60,
]
for (var i = 0; i &lt; 3; i++) {
for (var j = 1; j &lt;= 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]);
}
}
}
quantastica / quantum-circuit / lib / quantum-circuit.js View on Github
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