예제 #1
0
#!/usr/bin/python
## example9_8
import numpy as np
from householder import *
a = np.array([[ 7.0, 2.0,  3.0, -1.0],\
        [ 2.0, 8.0,  5.0,  1.0],  \
        [ 3.0, 5.0, 12.0,  9.0],  \
        [-1.0, 1.0,  9.0,  7.0]])

d, c = householder(a)
print("Principal diagonal {d}:\n", d)
print("\nSubdiagonal {c}:\n", c)
print("\nTransformation matrix [P]:")
print(computeP(a))
input("\nPress return to exit")
예제 #2
0
## example9_14
from householder import *
from eigenvals3 import *
from inversePower3 import *
from numarray import array, zeros, Float64, matrixmultiply

N = 3  # Number of eigenvalues requested
a = array([[ 11.0, 2.0,  3.0,  1.0,  4.0],  \
           [  2.0, 9.0,  3.0,  5.0,  2.0],  \
           [  3.0, 3.0, 15.0,  4.0,  3.0],  \
           [  1.0, 5.0,  4.0, 12.0,  4.0],  \
           [  4.0, 2.0,  3.0,  4.0, 17.0]])
xx = zeros((len(a), N), type=Float64)
d, c = householder(a)  # Tridiagonalize [A]
p = computeP(a)  # Compute transformation matrix
lambdas = eigenvals3(d, c, N)  # Compute eigenvalues
for i in range(N):
    s = lambdas[i] * 1.0000001  # Shift very close to eigenvalue
    lam, x = inversePower3(d, c, s)  # Compute eigenvector [x]
    xx[:, i] = x  # Place [x] in array [xx]
xx = matrixmultiply(p, xx)  # Recover eigenvectors of [A]
print "Eigenvalues:\n", lambdas
print "\nEigenvectors:\n", xx
raw_input("Press return to exit")
예제 #3
0
#!usr/bin/env python
from auxFuncSLE import *
from householder import *
from givens import *
from gramSchmidt import *

A = [[12, -51, 4], [6, 167, -68], [-4, 24, -41]]

# gramSchmidt
print "\nMetodo Gram Schmidt"
Q, R = gramSchmidt(A)
print "\tMatrix Q"
printMatrix(Q)
print "\tMatrix R"
printMatrix(R)
# householder
print "\nMetodo Householder"
Q, R = householder(A)
print "\tMatrix Q"
printMatrix(Q)
print "\tMatrix R"
printMatrix(R)
# givens
print "\nMetodo Givens"
Q, R = givens(A)
print "\tMatrix Q"
printMatrix(Q)
print "\tMatrix R"
printMatrix(R)
print
예제 #4
0
파일: example9_8.py 프로젝트: caitouwh/kod
## example9_8
from numarray import array,matrixmultiply
from householder import *

a = array([[ 7.0, 2.0,  3.0, -1.0],  \
           [ 2.0, 8.0,  5.0,  1.0],  \
           [ 3.0, 5.0, 12.0,  9.0],  \
           [-1.0, 1.0,  9.0,  7.0]])
d,c = householder(a)
print "Principal diagonal {d}:\n", d
print "\nSubdiagonal {c}:\n",c
print "\nTransformation matrix [P]:"
print computeP(a)
raw_input("\nPress return to exit")


예제 #5
0
파일: example9_14.py 프로젝트: caitouwh/kod
## example9_14
from householder import *
from eigenvals3 import *
from inversePower3 import *
from numarray import array,zeros,Float64,matrixmultiply

N = 3   # Number of eigenvalues requested
a = array([[ 11.0, 2.0,  3.0,  1.0,  4.0],  \
           [  2.0, 9.0,  3.0,  5.0,  2.0],  \
           [  3.0, 3.0, 15.0,  4.0,  3.0],  \
           [  1.0, 5.0,  4.0, 12.0,  4.0],  \
           [  4.0, 2.0,  3.0,  4.0, 17.0]])
xx = zeros((len(a),N),type=Float64)
d,c = householder(a)             # Tridiagonalize [A]
p = computeP(a)                  # Compute transformation matrix
lambdas = eigenvals3(d,c,N)      # Compute eigenvalues
for i in range(N):            
    s = lambdas[i]*1.0000001     # Shift very close to eigenvalue
    lam,x = inversePower3(d,c,s) # Compute eigenvector [x]
    xx[:,i] = x                  # Place [x] in array [xx]
xx = matrixmultiply(p,xx)        # Recover eigenvectors of [A]
print "Eigenvalues:\n",lambdas
print "\nEigenvectors:\n",xx
raw_input("Press return to exit")