In mathematics, the absolute value (or modulus) of a real number is its non-negative value regardless of its sign. Conceptually, it represents the distance of a number from zero on a number line.
The mathematical notation for absolute value uses two vertical bars: |x|. This means:
If x is positive or zero, |x| = x.
If x is negative, |x| = -x (which results in a positive number).
The Absolute Value Formula
The formal definition is piecewise:
|x| = x if x ≥ 0 |x| = -x if x < 0
Calculating Distance
The absolute value is extremely useful for finding the distance between two points on a one-dimensional line. The distance between a and b is calculated as |a – b|. Because of the properties of absolute values, |a – b| is always equal to |b – a|, ensuring distance is never negative.
Examples of Absolute Value
Positive Number: |15| = 15
Negative Number: |-7.2| = 7.2
Zero: |0| = 0
Subtraction: |10 – 25| = |-15| = 15
Practical Applications
Absolute values are used in various fields including:
Physics: Calculating displacement versus total distance traveled.
Statistics: Calculating the Mean Absolute Deviation (MAD) to understand data variability.
Engineering: Determining tolerance levels and error margins where the direction of the error is less important than its magnitude.
Computer Science: Graphics rendering and distance algorithms.
function calculateAbsoluteValue() {
var inputVal = document.getElementById("inputNumber").value;
var resultDiv = document.getElementById("absResult");
var displayDiv = document.getElementById("absDisplay");
if (inputVal === "") {
alert("Please enter a number.");
return;
}
var x = parseFloat(inputVal);
if (isNaN(x)) {
alert("Please enter a valid numeric value.");
return;
}
var absVal = Math.abs(x);
displayDiv.innerHTML = "| " + x + " | = " + absVal + "";
resultDiv.style.display = "block";
}
function calculateDistance() {
var valA = document.getElementById("pointA").value;
var valB = document.getElementById("pointB").value;
var resultDiv = document.getElementById("distResult");
var displayDiv = document.getElementById("distDisplay");
if (valA === "" || valB === "") {
alert("Please enter values for both Point A and Point B.");
return;
}
var a = parseFloat(valA);
var b = parseFloat(valB);
if (isNaN(a) || isNaN(b)) {
alert("Please enter valid numeric values.");
return;
}
var distance = Math.abs(a – b);
displayDiv.innerHTML = "| " + a + " – (" + b + ") | = " + distance + "";
resultDiv.style.display = "block";
}