One of the most basic operations in mathematics is solving a system of linear equations. Many sophisticated numerical techniques, such as the finite element method, are designed to reduce a complicated problem to a system of linear algebraic equations that must be solved. Let's see how vectors and matrices in Sage can make this easier. We will repeat the example from Chapter 1, and explain it in more detail:
Enter the following code in a worksheet. If you are using the interactive shell, you will need to have LaTeX installed to use the show
command. If you don't have LaTeX, replace show
with print
in this example and the ones that follow:
M4 = MatrixSpace(QQ, 4) # Rational numbers print("Identity matrix:") show(M4.identity_matrix()) A = M4.matrix([[0, -1, -1, 1], [1, 1, 1, 1], [2, 4, 1, -2], [3, 1, -2, 2]]) print("Matrix A:") show(A) b = vector(QQ, [0, 6, -1, 3]) # Rational numbers print("Vector b:") show(b) solution = A.solve_right...