eig.py
# coding=utf-8
#Numerical calculation library(LAPACK)
import numpy as np
#Random number library
import random
#10x10 zero matrix
A = np.zeros((10,10))
#Initialization
for i in range(10):
for j in range(10):
rand = random.randint(1,10)
A[i][j] = rand
A[j][i] = rand
print 'Computational symmetry matrix'
print A
l,v = np.linalg.eig(A)
print 'eigenvalue'
print l
print 'Eigenvector'
print v
It's really easy to do.
If it is true, the number of loops is redundant at the time of initialization of the real symmetric matrix, so I wanted to implement it as follows, but I gave up because all the diagonal terms became zero.
init
for i in range(10):
for j in range(i):
rand = random.randint(1,10)
if rand == 0:
ptint 1
A[i][j] = rand
A[j][i] = rand
I thought about investigating the cause, but I get angry with Syntax Error, so let's do it again
Numpy has LAPACK built in, but Matlab seems to have LAPACK built in the eigenvalue calculation part.
Recommended Posts