Linear Combinations
Description
We can use basic vector operations in Sage to build a linear combinations of vectors. Consider $\mathbf v_1 = (2, 3, 5)$, $\mathbf v_2 = (7, 11, 13)$, and $\mathbf v_3 = (17, 19, 23)$. The cell below computes the linear combination $\mathbf v_1 + 6 \mathbf v_2 - 2 \mathbf v_3$.
Sage Cell
Code
v1 = vector(QQ, [2, 3, 5])
v2 = vector(QQ, [7, 11, 13])
v3 = vector(QQ, [17, 19, 23])
v1 + 6*v2 - 2*v3
Options
Linear Combinations of matrices
We also compute linear combinations of matrices. However, matrix(QQ, [2, 3, 5]) + vector(QQ, [7, 11, 13]) will produce an error.
v2 = matrix(QQ, [7, 11, 13])
Code
v1 = matrix(QQ, [2, 3, 5])
v2 = matrix(QQ, [7, 11, 13])
v3 = matrix(QQ, [17, 19, 23])
v1 + 6*v2 - 2*v3
Tags
CC:
Primary Tags: Linear Algebra: Euclidean spaces
Secondary Tags: Euclidean spaces: Linear combinations
Related Cells
- Vectors in Sage. Vectors in Sage.
Attribute
Permalink:
Author:
Date: 10 Apr 2020 15:51
Submitted by: Zane Corbiere