Last active
August 29, 2015 14:21
-
-
Save matsuken92/2ad112ace8560a73ac30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.eig.html | |
#numpy.linalg.eig(a)[source] | |
#Compute the eigenvalues and right eigenvectors of a square array. | |
# | |
#Parameters: | |
#a : (..., M, M) array | |
#Matrices for which the eigenvalues and right eigenvectors will be computed | |
#Returns: | |
#w : (..., M) array | |
#The eigenvalues, each repeated according to its multiplicity. The eigenvalues are not necessarily ordered. The resulting array will be #always be of complex type. When a is real the resulting eigenvalues will be real (0 imaginary part) or occur in conjugate pairs | |
#v : (..., M, M) array | |
#The normalized (unit “length”) eigenvectors, such that the column v[:,i] is the eigenvector corresponding to the eigenvalue w[i]. | |
#Raises: | |
#LinAlgError : | |
#If the eigenvalue computation does not converge. | |
A = np.array( | |
[[ 2, 1], | |
[-0.5,-1.5]]) | |
la, v = np.linalg.eig(A) | |
print "la",la | |
print "v",v | |
print v[0][1]**2 + v[1][1]**2 | |
print v[0][1]**2 / v[1][1]**2 | |
# eig.rb | |
# (This code is reference of https://gist.github.com/maehrm/43058b429cdb179671c5) | |
## coding: utf-8 | |
#require 'matrix' | |
# | |
#a = Matrix[[2, 1], [-0.5, -1.5]] | |
#p a.eigensystem.eigenvalues # => [1.8507810593582121, -1.3507810593582121] | |
#p a.eigensystem.eigenvector_matrix # => Matrix[[0.9890493903846761, -0.31580578969441475], [-0.14758490227560742, 1.0581960585437078]] | |
ruby_v1 = -0.31580578969441475 | |
ruby_v2 = 1.0581960585437078 | |
print (ruby_v1)**2 + ruby_v2**2 | |
print (ruby_v1)**2 / ruby_v2**2 | |
# ---------- output -------------# | |
# la [ 1.85078106 -1.35078106] | |
# v [[ 0.98904939 -0.28597431] | |
# [-0.1475849 0.95823729]] | |
# 1.0 | |
# 0.089065168985 | |
# | |
# 1.21951219512 | |
# 0.089065168985 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment