Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Mathematics and Algorithms > Matrices and Linear Algebra > Operations on Vectors > UnitVector >
Mathematica > Mathematics and Algorithms > Graphs & Networks > Graph Programming > Matrices and Linear Algebra > Operations on Vectors > UnitVector >
Mathematica > Visualization and Graphics > Graphs & Networks > Graph Programming > Matrices and Linear Algebra > Operations on Vectors > UnitVector >

UnitVector

UnitVector[k]
gives the two-dimensional unit vector in the k^(th) direction.
UnitVector
gives the n-dimensional unit vector in the k^(th) direction.
  • UnitVector is a list of length n with a 1 in position k and 0s elsewhere.
  • UnitVector by default creates a vector containing exact integers.
  • The option WorkingPrecision can be used to specify the precision of vector components.
The unit vector in the direction in 2 dimensions:
The unit vector in the direction in 3 dimensions:
The unit vector in the direction in 2 dimensions:
In[1]:=
Click for copyable input
Out[1]=
 
The unit vector in the direction in 3 dimensions:
In[1]:=
Click for copyable input
Out[1]=
A unit vector in dimension 100:
A machine-precision unit vector in the direction in 2 dimensions:
A 50-digit-precision unit vector in the direction in 2 dimensions:
Find the matrix for a "black box" linear operator:
The matrix is equivalent to (though perhaps less efficient than) the "black box":
The matrix form allows you to use typical linear algebra functions:
p is a random permutation:
Get the permutation matrix:
Compute the unit matrices:
A random unit vector:
The length is equal to n:
There is a 1 in position k:
All other components are zero:
For very large dimensions, n, the vector given by UnitVector may use a lot of memory:
An alternative is to use a SparseArray to represent the same thing:
New in 6 | Last modified in 7
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team
Format:   HTML  |  CDF