In [2]:
# input:
A = matrix([
[1, -1, 2],
[-1, 1, 2],
[2, 2, -2]
])
#
Charakteristisches Polynom berechnen: $$P(\lambda) = det(A - \lambda I) = \begin{vmatrix} a_{1,1} - \lambda & a_{1,2} & \ldots & a_{1,n} \\ a_{2,1} & a_{2,2} - \lambda & \ldots & a_{2,n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{n,1} & a_{n,2} & \ldots & a_{n,n} - \lambda \\ \end{vmatrix}$$
In [3]:
e = var('e')
pem = (A - e * identity_matrix(*A.dimensions()))
show(pem)
In [15]:
pe = pem.det()
show(pe.simplify_full())
show((pe / (var('e') - 2)).simplify_full())
show(solve([(pe / (var('e') - 2))], e))
Lösen des Systems $P(\lambda) = 0$ ergibt die Eigenwerte:
In [5]:
EW = [x for x in solve([pe == 0], e)]
show(EW)
Bestimmung der Eigenvektoren $v_i$ zu den Eigenwerten $\lambda_i$ durch Lösen der Gleichungen $$(A - \lambda_{i} \cdot I) \cdot x = 0$$
In [6]:
for ew in EW:
show(ew)
m = pem.subs(e=ew).simplify_full()
for i in range(m.dimensions()[0]):
m[i,i] = m[i,i].rhs()
show(m, LatexExpr("\quad \leadsto \quad"), m.echelon_form())
m.echelonize()
xsym = vector([var("x{}".format(i)) for i in range(m.dimensions()[0])])
v = (m * xsym).simplify_full()
eqns = [v[i] == 0 for i in range(len(v))]
print "EV:"
show(*solve(eqns, *xsym))
print "\n"
Mit sage internals:
In [7]:
show(A.characteristic_polynomial())
In [8]:
show(A.eigenvalues())
In [9]:
for e in A.eigenvectors_left():
show(e[0])
for v in e[1]:
show(v)
print ""
In [10]:
for e in A.eigenvectors_right():
show(e[0])
for v in e[1]:
show(v)
print ""