Magnitude: Difference between revisions
(→Documentation: BQN) |
m (Text replacement - "<source" to "<syntaxhighlight") |
||
Line 1: | Line 1: | ||
{{Built-in|Magnitude|<nowiki>|</nowiki>}}, or '''Absolute Value''', is a [[monadic]] [[scalar function]] which gives the [[wikipedia:Absolute value|absolute value]] of a real or [[complex]] number. Magnitude shares the [[glyph]] < | {{Built-in|Magnitude|<nowiki>|</nowiki>}}, or '''Absolute Value''', is a [[monadic]] [[scalar function]] which gives the [[wikipedia:Absolute value|absolute value]] of a real or [[complex]] number. Magnitude shares the [[glyph]] <syntaxhighlight lang=apl inline>|</source> with the dyadic arithmetic function [[Residue]]. | ||
== Examples == | == Examples == | ||
< | <syntaxhighlight lang=apl> | ||
|0 1 2 ¯1 ¯2 | |0 1 2 ¯1 ¯2 | ||
0 1 2 1 2 | 0 1 2 1 2 | ||
Line 16: | Line 16: | ||
For real numbers, the magnitude equals the original number [[times]] (or [[Divide|divided]] by, for non-zero numbers) its [[Signum|sign]]. | For real numbers, the magnitude equals the original number [[times]] (or [[Divide|divided]] by, for non-zero numbers) its [[Signum|sign]]. | ||
< | <syntaxhighlight lang=apl> | ||
v←0 1E¯100 20 1E300 ¯1E¯100 ¯20 ¯1E300 | v←0 1E¯100 20 1E300 ¯1E¯100 ¯20 ¯1E300 | ||
(|v)≡v××v | (|v)≡v××v | ||
Line 26: | Line 26: | ||
For complex numbers, the magnitude is defined as the Euclidean distance from the number 0 on the [[wikipedia:Complex plane|complex plane]]. | For complex numbers, the magnitude is defined as the Euclidean distance from the number 0 on the [[wikipedia:Complex plane|complex plane]]. | ||
< | <syntaxhighlight lang=apl> | ||
Dist←{0.5*⍨+.×⍨9 11○⍵} ⍝ Square root of square sum of real and imaginary parts | Dist←{0.5*⍨+.×⍨9 11○⍵} ⍝ Square root of square sum of real and imaginary parts | ||
Dist¨ 0 1J2 ¯3J4 | Dist¨ 0 1J2 ¯3J4 | ||
Line 36: | Line 36: | ||
Any real or complex number is equal to the [[Times|product]] of its [[signum]] and magnitude. | Any real or complex number is equal to the [[Times|product]] of its [[signum]] and magnitude. | ||
< | <syntaxhighlight lang=apl> | ||
(⊢ ≡ ××|) 0 1 1E¯300 ¯2.5 0J3.5 ¯3J¯4 | (⊢ ≡ ××|) 0 1 1E¯300 ¯2.5 0J3.5 ¯3J¯4 | ||
1 | 1 |
Revision as of 21:30, 10 September 2022
|
|
Magnitude (|
), or Absolute Value, is a monadic scalar function which gives the absolute value of a real or complex number. Magnitude shares the glyph <syntaxhighlight lang=apl inline>|</source> with the dyadic arithmetic function Residue.
Examples
<syntaxhighlight lang=apl>
|0 1 2 ¯1 ¯2
0 1 2 1 2
|0J2 ¯3J¯4
2 5 </source>
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.
<syntaxhighlight lang=apl>
v←0 1E¯100 20 1E300 ¯1E¯100 ¯20 ¯1E300 (|v)≡v××v
1
(|v)=v÷×v
0 1 1 1 1 1 1 </source>
For complex numbers, the magnitude is defined as the Euclidean distance from the number 0 on the complex plane.
<syntaxhighlight lang=apl>
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
</source>
Any real or complex number is equal to the product of its signum and magnitude.
<syntaxhighlight lang=apl>
(⊢ ≡ ××|) 0 1 1E¯300 ¯2.5 0J3.5 ¯3J¯4
1
</source>