feat: Task 8 Eigenwert und Eigenvektor
This commit is contained in:
parent
55fdda73b9
commit
1890008cf3
73
src/lineare_algebra/task8.py
Normal file
73
src/lineare_algebra/task8.py
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
# %%
|
||||||
|
# Init Numpy
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
# Parameter
|
||||||
|
PR = 3
|
||||||
|
matrizen = [
|
||||||
|
np.array([[2, 0], [0, 3]]),
|
||||||
|
np.array([[1, 1], [2, 2]]),
|
||||||
|
np.array([[0, 6], [2, 0]]),
|
||||||
|
np.array([[0, -6], [2, 0]]),
|
||||||
|
np.array([[1, 0, 0], [2, 2, -1], [0, -3, 0]]),
|
||||||
|
np.array([[0, 1, 0], [0, 0, 1], [1, 0, 0]]),
|
||||||
|
]
|
||||||
|
|
||||||
|
# Berechnung
|
||||||
|
for A in matrizen:
|
||||||
|
EW, EV = np.linalg.eig(A) # EW=Eigenwert, EV=Eigenvektor
|
||||||
|
|
||||||
|
with np.printoptions(precision=PR):
|
||||||
|
# Ausgabe
|
||||||
|
print(f"\nMatrix =\n\n{A}\n\nEigenwerte = {EW}\n\nEigenvektoren = \n\n{EV}\n")
|
||||||
|
print(60 * "-")
|
||||||
|
|
||||||
|
# %%
|
||||||
|
# Init Sympy
|
||||||
|
import sympy as sp
|
||||||
|
from IPython.display import display, Math
|
||||||
|
|
||||||
|
# Konfiguration
|
||||||
|
sp.init_printing()
|
||||||
|
|
||||||
|
matrizen = [
|
||||||
|
sp.Matrix([[2, 0], [0, 3]]),
|
||||||
|
sp.Matrix([[1, 1], [2, 2]]),
|
||||||
|
sp.Matrix([[0, 6], [2, 0]]),
|
||||||
|
sp.Matrix([[0, -6], [2, 0]]),
|
||||||
|
sp.Matrix([[1, 0, 0], [2, 2, -1], [0, -3, 0]]),
|
||||||
|
sp.Matrix([[0, 1, 0], [0, 0, 1], [1, 0, 0]]),
|
||||||
|
]
|
||||||
|
|
||||||
|
# Berechnung
|
||||||
|
for A in matrizen:
|
||||||
|
[EV, EW] = (
|
||||||
|
A.diagonalize()
|
||||||
|
) # EV=Eigenvektoren in Matrixform; EW (Eigenwerte)=Einträge in Hauptdiagonale
|
||||||
|
|
||||||
|
ew = A.eigenvals() # Eigenwert und dessen Multiplizität
|
||||||
|
ev = A.eigenvects() # Eigenwert, Multiplizität und zugehöriger Eigenvektor
|
||||||
|
|
||||||
|
# Ausgabe
|
||||||
|
display(Math(rf"\text{{A = }}{sp.latex(A)}"))
|
||||||
|
display(
|
||||||
|
Math(
|
||||||
|
rf"\text{{Eigenwerte in Hauptdiagonale}}\\ \lambda\text{{ = }}{sp.latex(EW)}"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
display(
|
||||||
|
Math(
|
||||||
|
rf"\text{{Eigenvektoren in Matrixform}}\\ \vec{{E}}\text{{ = }}{sp.latex(EV)}"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
display(
|
||||||
|
Math(
|
||||||
|
rf"\text{{Eigenwert und dessen Multiplizität}}\\ \lambda\text{{ = }}{sp.latex(ew)}"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
display(
|
||||||
|
Math(
|
||||||
|
rf"\text{{Eigenwert, Multiplizität und zugehöriger Eigenvektor }}\\ \vec{{E}}\text{{ = }}{sp.latex(ev)}"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
print(100 * "-")
|
||||||
Loading…
x
Reference in New Issue
Block a user