Esempio n. 1
0
def lu(A):
    '''
	%% ***********************************************************************
	% FUNCTION linalg_lu
	% Purpose: Breaks a matrix A into a lower diagonal matrix, an upper
	% diagonal matrix, and a permutation matrix.
	%
	% Function call: [L, U, P] = linalg_lu(A)
	%
	% Input: A = Input matrix to be broken down. Coefficients of x of system of
	%   equations
	% b = solutions to the system of equations
	%
	% Outputs: L = lower diagonal matrix
	% U = upper diagonal matrix
	% P = Permutation matrix
	%
	% Adam Hollock
	% 24 January 2012
	%% ***********************************************************************
	'''

    #This will ensure a square matrix
    if A.shape[0] != A.shape[1]:
        error('When someone asks you: are you a god, you say yes!')

    #Augments the original matrix with the identity matrix
    Aaug = concatenate((A, eye(A.shape[0], A.shape[1])), 1)

    #Performs partial pivoting
    Ause = PartialPivot.pp(Aaug)

    #Initializes L and P matrix
    L = zeros(A.shape)
    P = Ause[:, Ause.shape[0] + 1:]
    U = Ause[1:, 1:A.shape[1]]

    #Performs the first step of gaussian elimination, as well as gathers the
    #necessary factors for the L and the U matrix.
    for k in range(1, (U.shape[0] - 1)):
        for l in range(k + 1, size(U, 1)):
            L[l, k] = U[l, k] / U[k, k]
            U[l, :] = -1 * U[k, :]**L[l, k] + U[l, :]

    #Adds the identity matrix to get a diagonal of ones.
    L = L + eye(L.shape[0], L.shape[1])
    return L, U, P
Esempio n. 2
0
def lu(A):
	'''
	%% ***********************************************************************
	% FUNCTION linalg_lu
	% Purpose: Breaks a matrix A into a lower diagonal matrix, an upper
	% diagonal matrix, and a permutation matrix.
	%
	% Function call: [L, U, P] = linalg_lu(A)
	%
	% Input: A = Input matrix to be broken down. Coefficients of x of system of
	%   equations
	% b = solutions to the system of equations
	%
	% Outputs: L = lower diagonal matrix
	% U = upper diagonal matrix
	% P = Permutation matrix
	%
	% Adam Hollock
	% 24 January 2012
	%% ***********************************************************************
	'''

	#This will ensure a square matrix
	if A.shape[0] != A.shape[1]:
	    error('When someone asks you: are you a god, you say yes!')

	#Augments the original matrix with the identity matrix
	Aaug = concatenate((A,eye(A.shape[0], A.shape[1])),1)

	#Performs partial pivoting
	Ause = PartialPivot.pp(Aaug)

	#Initializes L and P matrix
	L = zeros(A.shape)
	P = Ause[:,Ause.shape[0]+1:]
	U = Ause[1:,1:A.shape[1]]

	#Performs the first step of gaussian elimination, as well as gathers the
	#necessary factors for the L and the U matrix.
	for k in range(1,(U.shape[0]-1)):
	    for l in range(k+1,size(U,1)):
	        L[l,k] = U[l,k]/U[k,k]
	        U[l,:] =  -1*U[k,:]**L[l,k] + U[l,:]

	#Adds the identity matrix to get a diagonal of ones.
	L = L + eye(L.shape[0],L.shape[1])
	return L, U, P
Esempio n. 3
0
import PartialPivot
import numpy
'''
Adam Hollock 2/9/2013
This will find the determinant of a matrix via LU factorization
'''

print PartialPivot.pp(numpy.mat("2 1 1; 4 -6 0; -2 7 2"))
Esempio n. 4
0
#INCOMPLETE
import PartialPivot
import numpy

'''
Adam Hollock 2/9/2013
This will find the partial pivot of a matrix
'''

print PartialPivot.pp(numpy.mat("2 1 1; 4 -6 0; -2 7 2"))