Esempio n. 1
0
def lu(a):
    """
    Performe LU decomposition on the matrix a so A = L*U
    """
    dw = True
    if dw:

        def loop_body(l, u):
            c = get_iterator()
            l[c:, c - 1] = (u[c:, c - 1] / u[c - 1, c - 1:c])
            u[c:, c -
              1:] = u[c:, c - 1:] - l[c:, c - 1][:, None] * u[c - 1, c - 1:]

        u = a.copy()
        l = np.zeros_like(a)
        np.diagonal(l)[:] = 1.0
        loop.do_while(loop_body, u.shape[0] - 2, l, u)
        return (l, u)
    else:
        u = a.copy()
        l = np.zeros_like(a)
        np.diagonal(l)[:] = 1.0
        for c in range(1, u.shape[0]):
            l[c:, c - 1] = (u[c:, c - 1] / u[c - 1, c - 1:c])
            u[c:, c -
              1:] = u[c:, c - 1:] - l[c:, c - 1][:, None] * u[c - 1, c - 1:]
            np.flush()
        return (l, u)
Esempio n. 2
0
def gauss(a):
    """
    Performe Gausian elimination on matrix a without pivoting
    """

    dw = False
    if dw:

        def loop_body(a):
            c = get_iterator(1)
            x1 = a[c:, c - 1:]
            #            x2 = (a[c:, c - 1, None] / a[c - 1, c - 1:c, None])#[:, None]
            x2 = a[c:, c - 1] / a[c - 1, c - 1:c]
            #            x2 = a[c:, c - 1] / a[c - 1, c - 1:c]
            #            x2 = (a[c:, c - 1] / a[c - 1, c - 1:c])[:, None]
            x3 = a[c - 1, c - 1:]
            x1 = x1 - x2 * x3

        loop.do_while(loop_body, a.shape[0] - 2, a)
        a /= np.diagonal(a)[:, None]
        return a
    else:
        for c in range(1, a.shape[0]):
            x1 = a[c:, c - 1:]
            x2 = (a[c:, c - 1] / a[c - 1, c - 1:c])[:, None]
            x3 = a[c - 1, c - 1:]
            x1 = x1 - x2 * x3
            #            a[c:, c - 1:] = a[c:, c - 1:] - (a[c:, c - 1] / a[c - 1, c - 1:c]) * a[c - 1, c - 1:]
            np.flush()
        a /= np.diagonal(a)[:, None]
        return a
Esempio n. 3
0
def gauss(a):
    """
    Performe Gausian elimination on matrix a without pivoting
    """
    for c in xrange(1,a.shape[0]):
        a[c:,c-1:] = a[c:,c-1:] - (a[c:,c-1]/a[c-1,c-1:c])[:,None] * a[c-1,c-1:]
        np.flush(a)
    a /= np.diagonal(a)[:,None]
    return a
Esempio n. 4
0
def gauss(a):
    """
    Performe Gausian elimination on matrix a without pivoting
    """
    for c in xrange(1,a.shape[0]):
        a[c:,c-1:] = a[c:,c-1:] - (a[c:,c-1]/a[c-1,c-1:c])[:,None] * a[c-1,c-1:]
        np.flush(a)
    a /= np.diagonal(a)[:,None]
    return a
Esempio n. 5
0
def lu(a):
    """
    Performe LU decomposition on the matrix a so A = L*U
    """
    u = a.copy()
    l = np.zeros_like(a)
    np.diagonal(l)[:] = 1.0
    for c in xrange(1,u.shape[0]):
        l[c:,c-1] = (u[c:,c-1]/u[c-1,c-1:c])
        u[c:,c-1:] = u[c:,c-1:] - l[c:,c-1][:,None] * u[c-1,c-1:]
        np.flush(u)
    return (l,u)
Esempio n. 6
0
def lu(a):
    """
    Performe LU decomposition on the matrix a so A = L*U
    """
    u = a.copy()
    l = np.zeros_like(a)
    np.diagonal(l)[:] = 1.0
    for c in xrange(1,u.shape[0]):
        l[c:,c-1] = (u[c:,c-1]/u[c-1,c-1:c])
        u[c:,c-1:] = u[c:,c-1:] - l[c:,c-1][:,None] * u[c-1,c-1:]
        np.flush(u)
    return (l,u)