0
0
SciPydata~10 mins

Eigenvalues and eigenvectors (eig) in SciPy - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Eigenvalues and eigenvectors (eig)
Start with matrix A
Compute eigenvalues and eigenvectors
Eigenvalues (λ) found
Eigenvectors (v) found
Use λ and v for analysis or transformation
We start with a matrix, then calculate its eigenvalues and eigenvectors, which help us understand the matrix's key properties.
Execution Sample
SciPy
import numpy as np
from scipy.linalg import eig
A = np.array([[4, 2], [1, 3]])
values, vectors = eig(A)
print(values)
print(vectors)
This code calculates eigenvalues and eigenvectors of matrix A using scipy.linalg.eig.
Execution Table
StepActionMatrix AEigenvalues (λ)Eigenvectors (v)
1Input matrix A[[4, 2], [1, 3]]
2Calculate characteristic polynomialdet(A - λI) = 0
3Solve polynomial for λ[5.0, 2.0]
4Find eigenvectors for λ=5.0[[0.8944, 0.7071], [0.4472, -0.7071]]
5Find eigenvectors for λ=2.0[[0.8944, 0.7071], [0.4472, -0.7071]]
6Output eigenvalues and eigenvectors[[4, 2], [1, 3]][5.0, 2.0][[0.8944, 0.7071], [0.4472, -0.7071]]
7End
💡 All eigenvalues and eigenvectors computed for matrix A.
Variable Tracker
VariableStartAfter Step 3After Step 6
A[[4, 2], [1, 3]][[4, 2], [1, 3]][[4, 2], [1, 3]]
valuesNone[5.0, 2.0][5.0, 2.0]
vectorsNoneNone[[0.8944, 0.7071], [0.4472, -0.7071]]
Key Moments - 3 Insights
Why do eigenvectors have two columns?
Each column corresponds to an eigenvector for one eigenvalue, as shown in execution_table rows 4 and 5.
Why are eigenvalues sometimes complex numbers?
Eigenvalues can be complex if the matrix has no real eigenvalues; here they are real (row 3), but complex values can appear for other matrices.
What does the eigenvector represent physically?
It shows a direction that the matrix transformation stretches or shrinks without changing direction, as seen in rows 4 and 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3, what are the eigenvalues of matrix A?
A[5.0, 2.0]
B[4, 3]
C[0.8944, 0.4472]
D[1, 2]
💡 Hint
Check the 'Eigenvalues (λ)' column at step 3 in the execution_table.
At which step do we first see the eigenvectors computed?
AStep 2
BStep 4
CStep 3
DStep 6
💡 Hint
Look at the 'Eigenvectors (v)' column in the execution_table to find when vectors appear.
If matrix A was changed to [[0, -1], [1, 0]], what would likely happen to eigenvalues?
AThey would remain real numbers
BThey would be zero
CThey would become complex numbers
DThey would be the same as original
💡 Hint
Recall from key_moments that some matrices have complex eigenvalues.
Concept Snapshot
Eigenvalues and eigenvectors:
- Given matrix A, solve det(A - λI) = 0 for eigenvalues λ
- For each λ, find vector v where A v = λ v
- Use scipy.linalg.eig(A) to get values and vectors
- Eigenvalues can be real or complex
- Eigenvectors show directions unchanged by A
Full Transcript
This visual execution traces how to compute eigenvalues and eigenvectors of a matrix using scipy.linalg.eig. We start with matrix A, then calculate its eigenvalues by solving the characteristic polynomial. Next, eigenvectors are found for each eigenvalue. The execution table shows each step, including matrix input, polynomial solving, and eigenvector calculation. Variable tracking shows how values and vectors change from start to finish. Key moments clarify common confusions about eigenvector columns and complex eigenvalues. The quiz tests understanding of eigenvalues, eigenvector steps, and effects of matrix changes. The snapshot summarizes the process and key points for quick reference.