Magnitude (|
), or Absolute Value, is a monadic scalar function which gives the absolute value of a real or complex number. Magnitude shares the glyph |
with the dyadic arithmetic function Residue.
Examples
|0 1 2 ¯1 ¯2
0 1 2 1 2
|0J2 ¯3J¯4
2 5
Properties
The magnitude of any number is a non-negative real number.
For real numbers, the magnitude equals the original number times (or divided by, for non-zero numbers) its sign.
v←0 1E¯100 20 1E300 ¯1E¯100 ¯20 ¯1E300
(|v)≡v××v
1
(|v)=v÷×v
0 1 1 1 1 1 1
For complex numbers, the magnitude is defined as the Euclidean distance from the number 0 on the complex plane.
Dist←{0.5*⍨+.×⍨9 11○⍵} ⍝ Square root of square sum of real and imaginary parts
Dist¨ 0 1J2 ¯3J4
0 2.236067977 5
|0 1J2 ¯3J4
0 2.236067977 5
Any real or complex number is equal to the product of its signum and magnitude.
(⊢ ≡ ××|) 0 1 1E¯300 ¯2.5 0J3.5 ¯3J¯4
1
See also
External links
Documentation
APL built-ins [edit]
|
Primitives (Timeline) |
Functions
|
Scalar
|
Monadic
|
Conjugate ∙ Negate ∙ Signum ∙ Reciprocal ∙ Magnitude ∙ Exponential ∙ Natural Logarithm ∙ Floor ∙ Ceiling ∙ Factorial ∙ Not ∙ Pi Times ∙ Roll ∙ Type ∙ Imaginary ∙ Square Root ∙ Round
|
Dyadic
|
Add ∙ Subtract ∙ Times ∙ Divide ∙ Residue ∙ Power ∙ Logarithm ∙ Minimum ∙ Maximum ∙ Binomial ∙ Comparison functions ∙ Boolean functions (And, Or, Nand, Nor) ∙ GCD ∙ LCM ∙ Circular ∙ Complex ∙ Root
|
Non-Scalar
|
Structural
|
Shape ∙ Reshape ∙ Tally ∙ Depth ∙ Ravel ∙ Enlist ∙ Table ∙ Catenate ∙ Reverse ∙ Rotate ∙ Transpose ∙ Raze ∙ Mix ∙ Split ∙ Enclose ∙ Nest ∙ Cut (K) ∙ Pair ∙ Link ∙ Partitioned Enclose ∙ Partition
|
Selection
|
First ∙ Pick ∙ Take ∙ Drop ∙ Unique ∙ Identity ∙ Stop ∙ Select ∙ Replicate ∙ Expand ∙ Set functions (Intersection ∙ Union ∙ Without) ∙ Bracket indexing ∙ Index ∙ Cartesian Product ∙ Sort
|
Selector
|
Index generator ∙ Grade ∙ Index Of ∙ Interval Index ∙ Indices ∙ Deal ∙ Prefix and suffix vectors
|
Computational
|
Match ∙ Not Match ∙ Membership ∙ Find ∙ Nub Sieve ∙ Encode ∙ Decode ∙ Matrix Inverse ∙ Matrix Divide ∙ Format ∙ Execute ∙ Materialise ∙ Range
|
Operators |
Monadic
|
Each ∙ Commute ∙ Constant ∙ Replicate ∙ Expand ∙ Reduce ∙ Windowed Reduce ∙ Scan ∙ Outer Product ∙ Key ∙ I-Beam ∙ Spawn ∙ Function axis ∙ Identity (Null, Ident)
|
Dyadic
|
Bind ∙ Compositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner Product ∙ Determinant ∙ Power ∙ At ∙ Under ∙ Rank ∙ Depth ∙ Variant ∙ Stencil ∙ Cut ∙ Direct definition (operator) ∙ Identity (Lev, Dex)
|
Quad names
|
Index origin ∙ Comparison tolerance ∙ Migration level ∙ Atomic vector
|