📖 Scenario: You work as a data analyst for a company that studies vibrations in mechanical systems. You need to find the natural vibration modes of a system represented by a matrix.
🎯 Goal: Learn how to calculate eigenvalues and eigenvectors of a matrix using SciPy's eig function.
📋 What You'll Learn
Create a 2x2 matrix as a NumPy array
Import the eig function from scipy.linalg
Use eig to find eigenvalues and eigenvectors
Print the eigenvalues and eigenvectors
💡 Why This Matters
🌍 Real World
Eigenvalues and eigenvectors help engineers understand how structures vibrate and respond to forces.
💼 Career
Data scientists and engineers use eigen decomposition in signal processing, principal component analysis, and system stability analysis.
Progress0 / 4 steps
1
Create the matrix
Create a variable called matrix and set it to a 2x2 NumPy array with values [[4, 2], [1, 3]].
SciPy
Hint
Use np.array to create the matrix with the exact values.
2
Import the eig function
Import the eig function from the scipy.linalg module.
SciPy
Hint
Use from scipy.linalg import eig to import the function.
3
Calculate eigenvalues and eigenvectors
Use the eig function with the variable matrix to calculate eigenvalues and eigenvectors. Store the results in variables called eigenvalues and eigenvectors.
SciPy
Hint
Call eig(matrix) and unpack the result into eigenvalues and eigenvectors.
4
Print the eigenvalues and eigenvectors
Print the variables eigenvalues and eigenvectors to display the results.
SciPy
Hint
Use two print statements, one for eigenvalues and one for eigenvectors.
Practice
(1/5)
1. What do eigenvalues represent in the context of a matrix transformation?
easy
A. The sum of all matrix elements
B. The directions that change completely under the matrix
C. How much eigenvectors stretch or shrink when the matrix is applied
D. The inverse of the matrix
Solution
Step 1: Understand eigenvalues meaning
Eigenvalues measure the factor by which eigenvectors are stretched or shrunk when multiplied by the matrix.
Step 2: Compare options with definition
How much eigenvectors stretch or shrink when the matrix is applied correctly describes this stretching/shrinking effect. Other options describe unrelated concepts.
Final Answer:
How much eigenvectors stretch or shrink when the matrix is applied -> Option C
Quick Check:
Eigenvalues = stretch/shrink factor [OK]
Hint: Eigenvalues tell how vectors scale under the matrix [OK]
Common Mistakes:
Confusing eigenvalues with eigenvectors
Thinking eigenvalues are directions
Mixing eigenvalues with matrix sum
2. Which of the following is the correct way to import the function to compute eigenvalues and eigenvectors using scipy?
easy
A. from scipy.linalg import eig
B. import scipy.eigen as eig
C. from scipy.linalg import eigenvalues
D. import scipy.linalg.eig as eigen
Solution
Step 1: Recall scipy function for eigenvalues
The function to compute eigenvalues and eigenvectors is named 'eig' and is in scipy.linalg.
Step 2: Check import syntax
from scipy.linalg import eig correctly imports 'eig' from 'scipy.linalg'. Other options use incorrect module names or syntax.
Final Answer:
from scipy.linalg import eig -> Option A
Quick Check:
Correct import = from scipy.linalg import eig [OK]
Hint: Use 'from scipy.linalg import eig' to get eigenvalues [OK]
Common Mistakes:
Using wrong module names like scipy.eigen
Trying to import non-existent functions
Incorrect import syntax
3. What is the output of the following code?
import numpy as np
from scipy.linalg import eig
A = np.array([[2, 0], [0, 3]])
values, vectors = eig(A)
print(values)
medium
A. [2.+0.j 3.+0.j]
B. [0.+2.j 0.+3.j]
C. [5.+0.j 0.+0.j]
D. [2 3]
Solution
Step 1: Understand matrix and eig function
Matrix A is diagonal with values 2 and 3 on the diagonal. Eigenvalues of a diagonal matrix are the diagonal elements.
Step 2: Predict output of eig
scipy.linalg.eig returns eigenvalues as complex numbers, so output will be [2.+0.j 3.+0.j].
Final Answer:
[2.+0.j 3.+0.j] -> Option A
Quick Check:
Diagonal matrix eigenvalues = diagonal elements [OK]