Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Implementing Eigenvectors & Eigenvalues in Python | Section
Python Math Module Essentials: Trigonometry, Logarithms, and Constants - 1769704232288

Implementing Eigenvectors & Eigenvalues in Python

Свайпніть щоб показати меню

Computing Eigenvalues and Eigenvectors

12345678910111213
import numpy as np from numpy.linalg import eig # Define matrix A (square matrix) A = np.array([[2, 1], [1, 2]]) # Solve for eigenvalues and eigenvectors eigenvalues, eigenvectors = eig(A) # Print eigenvalues and eigenvectors print(f'Eigenvalues:\n{eigenvalues}') print(f'Eigenvectors:\n{eigenvectors}')

eig() from the numpy library computes the solutions to the equation:

Av=λvA v = \lambda v
  • eigenvalues: a list of scalars λ\lambda that scale eigenvectors;
  • eigenvectors: columns representing vv (directions that don't change under transformation).

Validating Each Pair (Key Step)

1234567891011121314151617
import numpy as np from numpy.linalg import eig # Define matrix A (square matrix) A = np.array([[2, 1], [1, 2]]) # Solve for eigenvalues and eigenvectors eigenvalues, eigenvectors = eig(A) # Verify that A @ v = λ * v for each eigenpair for i in range(len(eigenvalues)): print(f'Pair {i + 1}:') λ = eigenvalues[i] v = eigenvectors[:, i].reshape(-1, 1) print(f'A * v:\n{A @ v}') print(f'lambda * v:\n{λ * v}')

This checks if:

Av=λvA v = \lambda v

The two sides should match closely, which confirms correctness. This is how we validate theoretical properties numerically.

question mark

What does np.linalg.eig(A) return?

Виберіть правильну відповідь

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 39

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Секція 1. Розділ 39
some-alt