UnitVector¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
UnitVector[k]
gives the 2-D unit vector in the k-th direction.
UnitVector[n, k]
gives the n-D unit vector: a length-n list with a 1 in position k and 0s elsewhere.
Notes
Components are exact integers unless WorkingPrecision requests MachinePrecision or a digit count.Examples (3)¶
Every input below was run against the current Mathilda build and its output recorded.
Basic examples (2)¶
Options (1)¶
Algorithm¶
UnitVector — the n-dimensional unit vector in the k-th direction.
UnitVector[k] the 2-D unit vector in the k-th direction
(equivalent to UnitVector[2, k]).
UnitVector[n, k] the n-D unit vector: a length-n list with a 1 in
position k and 0s in every other position.
Components are exact integers by default (WorkingPrecision -> Infinity). The WorkingPrecision option selects the component representation, mirroring HilbertMatrix (src/linalg/hilbertmat.c):
WorkingPrecision -> Infinity exact integers (default)
WorkingPrecision -> MachinePrecision machine-precision Reals
WorkingPrecision -> d d-digit MPFR Reals (d above machine
precision; otherwise machine Reals)
Diagnostics mirror Wolfram's surface text:
- zero arguments -> UnitVector::argt (1 or 2 expected)
- non-option trailing argument -> UnitVector::nonopt
Non-integer or out-of-range (k < 1 or k > n) arguments leave the call unevaluated (return NULL), matching Mathilda's "can't evaluate" convention.
Implementation notes¶
Attributes: Protected.
References¶
- Source:
src/info.c - Specification:
docs/spec/builtins/lists-and-iteration.md - Tests:
tests/test_packed_list.c - Tests:
tests/test_unit_vector.c