Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Math 208 Interactive Notebooks © 2024 by Soham Bhosale, Sara Billey, Herman Chau, Zihan Chen, Isaac Hartin Pasco, Jennifer Huang, Snigdha Mahankali, Clare Minerath, and Anna Willis is licensed under CC BY-ND 4.0
License: OTHER
Image: ubuntu2204
© 2024 By Soham Bhosale, Sara Billey, Herman Chau, Zihan Chen, Isaac Hartin Pasco, Jennifer Huang, Snigdha Mahankali, Clare Minerath, and Anna Willis is licensed under CC BY-ND 4.0
Welcome to Chapter 3: The Paradise of Matrices
Originally created by |
Preface:
This Sage Worksheet is a part of a tutorial created by Prof. 's 2024 WXML group. Referred to , , this Worksheet is intended to help future students with some tools and software to present more visual linear algebra content. This Worksheet will revolve around of 's Book.
Next, let's take a look at matrix computations, which I believe are crucial in linear algebra. First, we'll explore matrix addition and subtraction.
Suppose we have matrices and . We want to calculate and .
Implementing this in Sage is quite straightforward, as follows:
To begin with, let's consider the computation of . Actually, it's the same as multiply scalar in every entries in matrix . We will computer by using sage as below.
In the last line, I also calculated . When we see , we should consider whether the result of is the same as that of . Let's give it a try.
The results are the same. For three matrices, does addition follow the commutative law? I encourage you to check this conclusion yourself, and you should find that it is correct. Next, let's take a look at matrix multiplication. I won't go into the specific steps of multiplication, as you can learn about them from reading relevant materials. What I want you to check now is whether matrix multiplication follows the commutative law.
Suppose we have two matrices and . Let's calculate and to see if the results of these two are the same.
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[5], line 6
4 print(str(F*G))
5 print("G*F is")
----> 6 G*F
, in sage.structure.element.Matrix.__mul__()
4088
4089 if BOTH_ARE_ELEMENT(cl):
-> 4090 return coercion_model.bin_op(left, right, mul)
4091
4092 cdef long value
, in sage.structure.coerce.CoercionModel.bin_op()
1276 # We should really include the underlying error.
1277 # This causes so much headache.
-> 1278 raise bin_op_exception(op, x, y)
1279
1280 cpdef canonical_coercion(self, x, y) noexcept:
TypeError: unsupported operand parent(s) for *: 'Full MatrixSpace of 2 by 3 dense matrices over Integer Ring' and 'Full MatrixSpace of 2 by 2 dense matrices over Integer Ring'
We observe that the result of cannot be produced, while yields a result. Does this, to some extent, explain why is not equal to ? This serves as a reminder that in the matrix multiplication of , the number of columns in matrix must be the same as the number of rows in matrix for the computation to be possible. Using this reminder, let's try to see if the multiplication of matrices follows the commutative law. We'll set and as .
Now, I think we can summarize our conclusion that matrix multiplication does not follow the commutative law. Similarly, we are curious about other properties like the associative law and distributive law, and we can also perform self-checks for these. Here, I'll use the distributive law as an example.
Suppose we have three matrices , where , , and . Let's check if holds true.
I think we have concluded on our own that matrix multiplication does comply with the distributive law. Let's continue to explore another important matrix operation: . The main idea of transpose is to switch coordinates. If we have a matrix , then would be . I'm sure you, being clever, have already spotted the pattern. Can you summarize it? For example, if the coordinates in are , what would the corresponding coordinates in be? Let's find the answer through an example.
Suppose we have a matrix , what should be? We can still implement this through Sage.
Matrix transpose also satisfies many properties. For example, and . We will use the following example to demonstrate the latter conclusion.
Let's calculate and for the given vectors: ,
Here, I'd like to pose a question to you. Do you know how to calculate the power of a matrix? Is matrix power simply raising each entry of the matrix to the corresponding power? In fact, this conclusion holds true for diagonal matrices, but not for non-diagonal matrices. However, don't worry, at this stage, we won't be calculating very high powers of matrices. If we encounter something like , we can simply compute instead. The specifics of calculating high powers of matrices will be covered in Chapter on .
I'd like to include the concept of in the matrix calculations discussed in section 3.2 because finding the inverse of a matrix is also a matrix operation. Let's consider a matrix :
We have a handy formula to find the inverse of this matrix:
However, for matrices larger than , there are methods to find the inverse, but it's often efficient to compute the inverse of a matrix using SageMath.
Let's take an example with a matrix : We will now find its inverse and verify our result by checking if .
So what we've found is the inverse of matrix . Of course, we won't stop here; knowledge of inverse matrices is not only applicable in this chapter but also comes into play in section , " ," particularly in the operations mentioned below:
Let's explore the second operation through a simple example.
Let's calculate and .
We can observe that they are the same. How can you remember this formula, and why is it to first find the inverse of and then multiply it by the inverse of ? Let's think about a process: when you define as putting on your socks and as putting on your shoes, when we want to undo these steps, you should first take off your shoes, and then take off your socks. In other words, .
ParseError: KaTeX parse error: Can't use function '$' in math mode at position 7: 3.5^*-$̲$Markov
What is a Markov matrix? I believe the most important thing is that it satisfies two conditions. The first is that the matrix is non-negative, which means that every entry in the Markov matrix should be greater than or equal to . Another important property of a Markov matrix is that the sum of each of its columns is equal to . A Markov matrix is a fascinating matrix, and I'll do my best to introduce you to some Markov matrices that I know.
First, we can generate matrices that satisfy the above properties randomly. Each run will produce a different matrix because it's a random process.
Observe the randomly generated matrices above and determine whether each generation results in a Markov matrix. I would like to discuss a fascinating property of Markov matrices, which is that the product of two Markov matrices is still a Markov matrix. We will also verify this property using randomly generated matrices.
We have observed through the multiplication of multiple random matrices that Markov matrices do indeed exhibit this characteristic. Can you think of why? (Hint: You can try using the row vector multiplied on the far left.) For Markov matrices, what we are most concerned with is their contribution to studying long-term behavior. Let's look at a specific example below.
By observing the eigenvalues we have outputted, we can see that the absolute values of the other two eigenvalues are all within , meaning that the absolute values of the other eigenvalues do not exceed . Another thing we can observe is that only the dominant eigenvector is a non-negative vector.
Super cool! It seems like we've discovered a fascinating aspect of Markov matrices. Taking a closer look at the dominant eigenvector above, you'll notice that it's just a scalar multiple of the dominant eigenvector! Isn't that intriguing? Indeed, we can use this to study long-term behavior! I can't wait to share with you how it works in google pagerank.
Compute the page rank of the webpages you see in the following directed graph. An arrow from to indicates that page links to page . Use the rule that when you are at a webpage you will teleport with probability and follow a link with probability . Assume that all links from a page have equal probability of being followed.
Based on the instructions in the question and with reference to the diagram, we can construct the following matrices:
= , =
Now, the matrix that combines these with teleportation, known as the transition matrix with teleportation, can be represented as: = +
We will calculate this transition matrix using Sage:
Maybe we need to rescale it to make sure the probability is , but maybe we can figure out the order of preference for these sites directly from the first column of dominant eigenvector, which we call the page rank vector.That is
It represents the relationship between matrix decomposition and permutation, commonly used in linear algebra and numerical analysis. Let me explain the meaning of each symbol:
- "" stands for the , which represents the permutation of rows. The matrix is a square matrix with the characteristic that each row and each column have exactly one element equal to , and all other elements are . The position of this indicates the row permutation, i.e., the reordering of rows in the original matrix.
- "" represents the original matrix, which is the matrix that needs to undergo decomposition.
- "" represents the lower triangular matrix, which is the lower triangular part of the decomposition, with all elements above the main diagonal being , and some elements below the main diagonal may be non-zero. The matrix is used to represent the lower triangular part of the original matrix .
- "" represents the upper triangular matrix, which is the upper triangular part of the decomposition, with all elements below the main diagonal being , and some elements above the main diagonal may be non-zero. The U matrix is used to represent the upper triangular part of the original matrix .
Dear linear algebraist:This is the end of my introduction to the matrix, thank you for your use, I hope this tool can help you more or less a little, I hope everything goes well with your future studies, if you encounter any problems, feel free to contact me:)
Best Regards,
Zihan@UW