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 used
Note 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 is 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 base rings based on the datatype of the components of the vector. While working in a specific ring, we need to explicitly pass the ring when instantiating a vector using the
vector command.
Note that \(ZZ\) is Sage notation for Integer numbers. Similarly, \(QQ\) is for Rational numbers, \(RR\) for Real numbers, and \(CC\) for Complex numbers. The method
base_ring returns the base ring of the vector.
If the ring type is omitted, Sage will infer the ring from the datatype of the vector components.
Sage also supports complex vectors. 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 whose components are complex numbers, we can either explicitly specify the ring as \(CC\text{,}\) or implicitly by using complex numbers as components of the vector as seen 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 the Sage default
plot method.
Sage also provides alternative methods to represent vectors visually. For instance, the
arrow method can be used to create an arrow representation of a vector in 3D space like in the following example.
Similarly, the
arrow2d method can be used to create an arrow representation of a vector in 2D space like in the following example.
Note that both methods take points coordinates as input (the beginning and end of the vector), as it can also take vectors as input. In which case, the arrow goes from the end of the first vector to the end of the second vector, like in the following example.
