Book Image

Sage Beginner's Guide

By : Craig Finch
1 (1)
Book Image

Sage Beginner's Guide

1 (1)
By: Craig Finch

Overview of this book

Table of Contents (17 chapters)
Sage Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – manipulating matrices


Let's try some elementary row operations to see how they work. Evaluate the following code:

 A = Matrix(QQ, [[1, 2, 3], [4, 5, 6], [7, 8, 9]])
print("Matrix A:")
show(A)

# Elementary row operations
print("Scaling second row by two:")
A.rescale_row(1, 2)
show(A)

print("Swapping first and second rows:")
A.swap_rows(0, 1)
show(A)

print("Adding 3*(row 1) to row 0:")
A.add_multiple_of_row(0, 1 ,3)
show(A)

print("A in echelon form:")
show(A.echelon_form())

The result will look like this:

What just happened?

We defined a matrix A and used its methods to perform some elementary row operations. You could use a sequence of these operations to reduce a matrix to echelon form. However, it's much easier to let Sage take care of that by using the echelon_form method.

Pop quiz – manipulating matrices

Test your understanding of selecting elements and parts of matrices. For the matrix defined below, what will the output be from each of these operations? Check your...