faddeev_leverrier.py
faddeev_leverrier.py — Python Source, 2Kb
Contenido del Archivo
# EL SIGUIENTE SCRIPT PERMITE CONSTRUIR EL POLINOMIO CARCTERISTICO DE UNA # DADA MATRIZ A TRAVES DEL ALGORITMO DE FADDEEV - LEVERRIER Y DETERMINAR SUS # RAICES (AUTOVALORES) # # (https://en.wikipedia.org/wiki/Faddeev%E2%80%93LeVerrier_algorithm) import math as mth #[1,2] import numpy as np #[1,3] A = np.array([[3,1],[8,3]]) #[4] n = 2 #[5,6] C = np.zeros(n+1) #[7] M = list([]) #[8] for k in range(0,n+1): #[9] if k == 0: M.append(np.zeros((n,n))) #[8] C[n-k] = 1 else: M.append(np.dot(A,M[k-1])+np.dot(C[n-k+1],np.identity(n))) #[10,11] C[n-k] = -1/k*np.trace(np.dot(A,M[k])) #[12] C = np.fliplr([C])[0] #[13] pol= str("p(x) = ") for i in range(n+1): pol = pol + "("+ str(C[i]) + ")"+ " * x^"+str(n-i)+" + " print("Polinomio caracteristico:","\n",pol[:-8]) print("\n") print("Autovalores:","\n",np.roots(C)) #[14] # REFERENCIAS # [ 1 ] MODULOS: http://webs.ucm.es/info/aocg/python/lenguaje_programacion/index.html#modulos # [ 2 ] MATH: https://programacion.net/articulo/modulos_matematicos_en_python_math_y_cmath_1750 # [ 3 ] NUMPY: http://webs.ucm.es/info/aocg/python/modulos_cientificos/numpy/index.html # [ 4 ] NUMPY.ARRAY: https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.array.html?highlight=array#numpy.array # [ 5 ] NUMPY.NDARRAY.SIZE: https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.ndarray.size.html?highlight=size#numpy-ndarray-size # [ 6 ] MATH.SQRT: https://docs.python.org/2/library/math.html#power-and-logarithmic-functions # [ 7 ] NUMPY.ZEROS: https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.zeros.html#numpy.zeros # [ 8 ] LISTAS Y TUPLAS: http://webs.ucm.es/info/aocg/python/lenguaje_programacion/index.html#listas-y-tuplas # [ 9 ] RANGE: http://webs.ucm.es/info/aocg/python/lenguaje_programacion/index.html#listas-por-comprension # [ 10 ] NUMPY.DOT: https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.dot.html?highlight=dot#numpy.dot # [ 11 ] NUMPY.IDENTITY: https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.identity.html # [ 12 ] NUMPY.TRACE: https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.trace.html?highlight=trace#numpy.trace # [ 13 ] NUMPY.FLIPLR: https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.fliplr.html?highlight=flip#numpy.fliplr # [ 14 ] NUMPY.ROOTS: https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.roots.html