[Python] 特徵值
我只解出一元二次、三次方程式 . . . 我好爛 import math as math def toFactor(matrix) : length = len(matrix) if length == 4 : a, b = matrix[0], matrix[1] c, d = matrix[2], matrix[3] A = 1 B = (a+d) * (-1) C = a*d - b*c return A,B,C if length == 9 : a, b, c = matrix[0], matrix[1], matrix[2] d, f, g = matrix[3], matrix[4], matrix[5] h, j, l = matrix[6], matrix[7], matrix[8] A = 1 B = - a - f - l C = - b*d + a*f - c*h - g*j + a*l + f*l D = c*f*h + b*g*h + c*d*j + a*g*j + b*d*l - a*f*l return A,B,C,D if length == 16 : a, b, c, d = matrix[0], matrix[1], matrix[2], matrix[3] f, g, h, j = matrix[4], matrix[5], matrix[6], matrix[7] l, m, o, p = matrix[8], matrix[9], matrix[10], matrix[11] q, r, s, t = matrix[12], matrix[13], matrix[14], matrix[15] A = 1 B = - a - g - o - t C = - b*f + a*g - c*l - h*m + a*o + g*o - d*q - j*r - p*s + a*t + g*t + o*t D = ( c*g*l - b*h*l - c*f*m + a*h*m + b*f*o - a*g*o + d*g*q - b*j*q + d*o*q - c*p*q - d*f*r + a*j*r + j*o*r - h*p*r - d*l*s - j*m*s + a*p*s + g*p*s + b*f*t - a*g*t + c*l*t + h*m*t - a*o*t - g*o*t) E = (d*h*m*q - c*j*m*q - d*g*o*q + b*j*o*q + c*g*p*q - b*h*p*q - d*h*l*r + c*j*l*r + d*f*o*r - a*j*o*r - c*f*p*r + a*h*p*r + d*g*l*s - b*j*l*s - d*f*m*s + a*j*m*s + b*f*p*s - a*g*p*s - c*g*l*t + b*h*l*t + c*f*m*t - a*h*m*t - b*f*o*t + a*g*o*t) return A,B,C,D,E def solveFunction(f) : length = len(f) if length == 3 : A, B, C = f[0],f[1],f[2] x1 = ( -B + (B*B - 4*A*C)**(1/2)) / (2*A) x2 = ( -B - (B*B - 4*A*C)**(1/2)) / (2*A) return x1,x2 if length == 4 : A, B, C, D = f[0], f[1], f[2], f[3] p = ( -(B*B) / (3*A*A) ) + (C/A) q = ( (2*B*B*B) / (27*A*A*A) ) - ((B*C) / (3*A*A)) + (D/A) w = complex(-1,3**(1/2)) / 2 U = (-q / 2) + ( ( ( q / 2 )**2 + ( p / 3 )**3 )**(1/2) ) V = (-q / 2) - ( ( ( q / 2 )**2 + ( p / 3 )**3 )**(1/2) ) if U > 0 : U = math....