Created
November 6, 2015 08:33
-
-
Save ahrzb/ec3666dbfd70c2d48944 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
import numpy as np | |
import math | |
r = np.random.randint(0, 30, (3, 3)).astype('d') | |
def spectral_radius(m): | |
return max(abs(y) for y in np.linalg.eigvals(m)) | |
def matrix_norm2(m): | |
return math.sqrt(spectral_radius(m.dot(m.T))) | |
def matrix_sensitivity(m): | |
return matrix_norm2(m) * matrix_norm2(np.linalg.inv(m)) | |
d = (1 / np.diag(r)) * np.eye(3) | |
print "Matrix" | |
print r | |
print "Condition Number:", matrix_sensitivity(r) | |
print "D" | |
print d | |
print "Well Conditioned" | |
print d.dot(r) | |
print "Condition Number:", matrix_sensitivity(d.dot(r)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment