Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eigenvectors and eigevalues lecture ex needs improving #544

Open
jstac opened this issue Aug 5, 2024 · 3 comments
Open

Eigenvectors and eigevalues lecture ex needs improving #544

jstac opened this issue Aug 5, 2024 · 3 comments

Comments

@jstac
Copy link
Contributor

jstac commented Aug 5, 2024

Regarding the first exercise in https://intro.quantecon.org/eigen_I.html, we need to make clear exactly what the reader should try to do. Steps:

  1. Clarify the algorithm.
  2. Give the reader a specific matrix and ask them to verify that the spectral radius is approximately x using the algorithm.

(That way they get the satisfaction of computing something before they check the solution.)

@longye-tian
Copy link
Collaborator

longye-tian commented Aug 7, 2024

Dear John @jstac ,

Here is a version of the exercise I updated:


Power iteration is an algorithm used to compute the dominant eigenvalue of a diagonalizable $n \times n$ matrix $A$.

The method proceeds as follows:

  1. Choose an initial random $n \times 1$ vector $b_0$.
  2. Multiply $A$ by $b_k$ to obtain $Ab_k$.
  3. Approximate the eigenvalue as $\lambda_k = \max|Ab_k|$.
  4. Normalize the result: $b_{k+1} = \frac{Ab_k}{\max|Ab_k|}$.
  5. Repeat steps 2-4 for $m$ iterations and $\lambda_k$, $b_k$ will converge to the dominant eigenvalue and its eigenvectors of $A$.

A thorough discussion of the method can be found here.

Implement the power iteration method using the following matrix and initial vector:

$$ A = \begin{bmatrix} 1 & 0 & 3 \\ 0 & 2 & 0 \\ 3 & 0 & 1 \end{bmatrix}, \quad \mathbf{b}_0 = \begin{bmatrix} 1 \\ 1 \\ 1 \end{bmatrix} $$

Set the number of iterations to $m = 20$ and compute the dominant eigenvalue of $A$.


The solution for this exercise to match with the question

def power_iteration(A=np.array([[1, 0, 3],
              [0, 2, 0],
              [3, 0, 1]]), b=np.array([1,1,1]), m=20):
    
    for i in range(m):
        b = np.dot(A, b)
        lambda_1 = abs(b).max()
        b = b/ b.max()
    
    print('Eigenvalue:', lambda_1)
    print('Eigenvector:', b)

power_iteration()

What do you think about this update? Would you like to change anything?

Best ❤️
Longye

@jstac
Copy link
Contributor Author

jstac commented Aug 9, 2024

Hi @LongYe, this is great, many thanks!

I suggest replacinng "Multiply..." with "At the $k$-th iteration, multiply..."

Just to comply with the style manual, please use $b_0$ rather than $\mathbf b_0$.

@longye-tian
Copy link
Collaborator

Hi @LongYe, this is great, many thanks!

I suggest replacinng "Multiply..." with "At the k -th iteration, multiply..."

Just to comply with the style manual, please use b 0 rather than b 0 .

Sure thing. I will submit a PR for this issue and incorporate these suggestions. Thanks John!

Best ❤️
Longye

longye-tian added a commit that referenced this issue Aug 15, 2024
Dear John @jstac ,

This pull request is to update the exercise 1 and its answer in eigen_I.md according to #544 .

Best
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants