Section 2.1 Vectors
In this section, we will see how to define vectors, and perform basic operations on them.
Sage provides built-in support for vectors. In Sage, vectors are represented as \(n\)-tuples, \((v_1, v_2, ..., v_n) \in R^n\) where \(n\) is the number of components in the vector. Vectors can be defined using
vector
command, and passing the values of the vectors components.The number of components \(n\) of a vector \(v = (v_1, \dots, v_n)\) is obtained in Sage by using the command
degree
.To retrieve the components of a vector as a list, the method
list
can be usedNote that the return type of that command is the Python built-in
List
type; an ordered list of numbers where the order matters. As such, any and all native list methods can be used on the returned value.Recall that lists in Sage are 0-indexed, meaning that the first element of the list is at index 0. To access a specific component of a vector, we can use vector indexing method. Here how to access the first component of the vector \(v\text{.}\)
The magnitude of a vector, \(||v|| = \sqrt{v_1^2 + v_2^2 + ... + v_n^2}\) is obtained in Sage by using the vector method
norm
.A vector in \(R^{n+1}\) can be constructed from a vector in \(R^n\) by appending the values for the additional components.
Vectors in Sage can be created in different fields based on the datatype of the components of the vector. While working in a specific field, we need to explicitly pass the field when instantiating a vector using the
vector
command. Note that \(ZZ\) is Sage notation for the Integers field. Similarly, \(QQ\) is for Rational numbers, \(RR\) for Reals, and \(CC\) for Complex numbers. The method
base_ring
returns the base ring of the vector.If the field is omitted, Sage will infer the field from the datatype of the vector components.
Sage also supports vectors over the complex field \(CC\text{.}\) While such vectors are not commonly encountered in elementary linear algebra, they play an essential role in many engineering applications. For instance, in signal processing, orthogonal signals are frequently expressed as complex vectors, enabling the use of a single transformation matrix to act on the entire set, rather than applying the transformation to each signal individually.
To create a vector in the complex field, we can either explicitly specify the field as \(CC\text{,}\) or implicitly by using complex numbers as components of the vector like below.
In Sage, the complex conjugate of a vector is found by calling the
conjugate()
method on the vector itself. In low dimensions (\(n \leq 3\)), the geometrical representation of a vector can be visualized as an arrow starting from the origin to the point \(P=(v_1, v_2, ..., v_n)\text{.}\) Although Sage accepts vectors of any dimension, the visual representation is only possible and meaningful in 2D and 3D, and high dimensional vectors are to be taken as abstract objects.
To display a vector in Sage, we can use the internal method
plot
of vector class.Note that we can also obtain the same visual representation using Sage default
plot
method.