Advertisement
Guest User

solve roots of nth root polynomial

a guest
Apr 19th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. import numpy as np
  2.  
  3. def characteristic_matrix(coeffs):
  4.     n = coeffs.size-1
  5.     A = np.eye(n, k=1);
  6.  
  7.     print -(1/coeffs[0]) * coeffs[-1:0:-1]
  8.     A[-1,::] = -1 * (coeffs[-1:0:-1]/coeffs[0])
  9.     return A
  10.  
  11. def get_real_roots(coeffs):
  12.     A=characteristic_matrix(coeffs)
  13.     print A
  14.     start = time.time()
  15.     E,Q=np.linalg.eig(A)
  16.     end = time.time()
  17.  
  18.     print "Solved in:"
  19.     print end-start
  20.  
  21.     return E
  22.  
  23. get_real_roots(np.array([-3.0, 0.0, 5.0, -1.0, 0.0])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement