21 a = mat[0, 0] + mat[1, 1]
22 delta = (mat[0, 0] - mat[1, 1])**2 + 4 * mat[0, 1]**2
25 (a / 2, delta < 1e-10),
26 ((a - sqrt(delta)) / 2.0,
True)
30 (a / 2, delta < 1e-10),
31 ((a + sqrt(delta)) / 2.0,
True)
34 return tmp1.subs(delta, delta), tmp2.subs(delta, delta)
38 b = mat[0] + mat[4] + mat[8]
39 t =
sqr(mat[1]) +
sqr(mat[2]) +
sqr(mat[5])
40 p = 0.5 * (
sqr(mat[0] - mat[4]) +
sqr(mat[0] - mat[8]) +
sqr(mat[4] - mat[8]))
42 q = 18.0 * (mat[0] * mat[4] * mat[8] + 3.0 * mat[1] * mat[2] * mat[5])
43 q += 2.0 * (mat[0] *
sqr(mat[0]) + mat[4] *
sqr(mat[4]) + mat[8] *
sqr(mat[8]))
45 q -= 3.0 * (mat[0] + mat[4]) * (mat[0] + mat[8]) * (mat[4] + mat[8])
46 q -= 27.0 * (mat[0] *
sqr(mat[5]) + mat[4] *
sqr(mat[2]) + mat[8] *
sqr(mat[1]))
53 ((b + p * cos(delta / 3.0)) / 3.0,
True)
58 ((b + p * cos((delta + 2.0 * pi) / 3.0)) / 3.0,
True)
63 ((b + p * cos((delta - 2.0 * pi) / 3.0)) / 3.0,
True)
66 return tmp1.subs(p, p), tmp2.subs(p, p), tmp3.subs(p, p)