Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- #Determinar a Inversa de A
- import numpy as np
- import pylab as pl
- epsilon = 0.1
- A = 0.5* np.array([1+epsilon, 1-epsilon, 1, 1]).reshape(2,2) #matriz esta definida
- def isSquare (m): return all (len (row) == len (m) for row in m)
- def determinante(a):
- if not isSquare(a):
- return False
- return a[0,0]*a[1,1] - a[1,0]*a[0,1]
- def inversa(a):
- det = determinante(a)
- inv = np.array( [a[1,1],-1*a[0,1],-1*a[1,0],a[0,0] ]).reshape(2,2)
- return 1./det * inv
- def modulo(a): #Modulo de Frobenius
- return np.sqrt(np.sum(a*a))
- def cond(a):
- mod1 = modulo(inversa(a))
- mod2 = modulo(a)
- return mod1 * mod2
- # Parte do MAIN
- print 'Inversa'
- print inversa(A)
- set_e = np.linspace(0.001, 0.1, 300)
- c_nr = np.zeros(np.size(set_e))
- for l in np.arange(np.size(c_nr)):
- epsilon = set_e[l]
- A = 0.5* np.array([1+epsilon, 1-epsilon, 1, 1]).reshape(2,2)
- c_nr[l] = cond(A)
- pl.figure()
- pl.plot(set_e, c_nr)
- pl.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement