Ejemplo n.º 1
0
def stdForm(a, b):
    def invert(L):  # Inverts lower triangular matrix L
        n = len(L)
        for j in range(n - 1):
            L[j, j] = 1.0 / L[j, j]
            for i in range(j + 1, n):
                L[i, j] = -np.dot(L[i, j:i], L[j:i, j]) / L[i, i]
        L[n - 1, n - 1] = 1.0 / L[n - 1, n - 1]

    n = len(a)
    L = choleski(b)
    invert(L)
    h = np.dot(b, np.inner(a, L))
    return h, np.transpose(L)
Ejemplo n.º 2
0
def stdForm(a, b):
    def invert(L):  # Inverts lower triangular matrix L
        n = len(L)
        for j in range(n - 1):
            L[j, j] = 1.0 / L[j, j]
            for i in range(j + 1, n):
                L[i, j] = -dot(L[i, j:i], L[j:i, j]) / L[i, i]
        L[n - 1, n - 1] = 1.0 / L[n - 1, n - 1]

    n = len(a)
    L = choleski(b)
    invert(L)
    h = matrixmultiply(b, matrixmultiply(a, transpose(L)))
    return h, transpose(L)
Ejemplo n.º 3
0
def stdForm(a, b):
    def invert(L):  # Inverts lower triangular matrix L
        n = len(L)
        for j in range(n - 1):
            L[j, j] = 1.0 / L[j, j]
            for i in range(j + 1, n):
                L[i, j] = -dot(L[i, j:i], L[j:i, j]) / L[i, i]
        L[n - 1, n - 1] = 1.0 / L[n - 1, n - 1]

    n = len(a)
    L = choleski(b)
    invert(L)
    h = matrixmultiply(b, matrixmultiply(a, transpose(L)))
    return h, transpose(L)
Ejemplo n.º 4
0
# [ 1.66666667  2.66666667  2.66666667]
#
######################################################
k = np.array([1, 2, 1, 1, 2], np.float64)
W = np.array([2, 1, 2], np.float64)
a = np.zeros((3, 3))
a[0, 0] = k[0] + k[1] + k[2] + k[4]
a[0, 1] = -k[2]
a[0, 2] = -k[4]
a[1, 0] = -k[2]
a[1, 1] = k[2] + k[3]
a[1, 2] = -k[3]
a[2, 0] = -k[4]
a[2, 1] = -k[3]
a[2, 2] = k[3] + k[4]
L = choleski(a)
x = choleskiSol(L, W)
print("Displacements are (in units of W/k):\n\n", x)
print("--------------------------------------------")

## problem2_2_17
######################################################
# 1. Populate a and b below with the values from
#    problem 17 on page 82.
#
# Correct Outputs:
# R = 5.0 ohms
# The currents are (in amps):
# [ 2.82926829 1.26829268 4.97560976]
# R = 10.0 ohms
# The currents are (in amps):
Ejemplo n.º 5
0
#!/usr/bin/python
## example2_8
from numarray import array,matrixmultiply,transpose
from choleski import *

a = array([[ 1.44, -0.36,  5.52,  0.0], \
           [-0.36, 10.33, -7.78,  0.0], \
           [ 5.52, -7.78, 28.40,  9.0], \
           [ 0.0,   0.0,   9.0,  61.0]])
L = choleski(a)
print 'L =\n',L
print '\nCheck: L*L_transpose =\n', \
      matrixmultiply(L,transpose(L))
raw_input("\nPress return to exit")  
Ejemplo n.º 6
0
#!/usr/bin/python3
## example2_8 on p. 54

import os
from numpy import linalg,array,dot,transpose
from choleski import *

os.system('clear')  # This is handy for clearing the console screen

A = array([[ 1.44, -0.36,  5.52,  0.0], \
           [-0.36, 10.33, -7.78,  0.0], \
           [ 5.52, -7.78, 28.40,  9.0], \
           [ 0.0,   0.0,   9.0,  61.0]])
A_old=A.copy()
L = choleski(A)  # original contents of A overwritten
B=dot(L,transpose(L))
print ('A =\n',A_old)
print ('L =\n',L)
print ('\nCheck: L*L_transpose =\n', B)
print('\nError in decomposition = ',linalg.norm(A_old-B))
input("\nPress return to exit")