Пример #1
0
def seidel(a, b, coeff=1., eps=1e-10, limit=1000):
    if not checkSize(a, b):
        raise Exception("Invalid operands")
    a = deepcopy(a)
    b = deepcopy(b)
    n = shape(a)[0]
    for i in range(n):
        if a[i, i] == 0:
            raise Exception("Powerless method")
        b[i] /= a[i, i]
        a[i] /= a[i, i]
    x = zeroTerm(n)
    iters = 0
    maxNorm = 1e100 * n
    while norm(a * x - b) > eps:
        nextX = deepcopy(x)
        for i in range(n):
            nextX[i] -= a[i] * nextX - b[i]
        x += coeff * (nextX - x)
        iters += 1
        curNorm = norm(a * x - b)
        if iters >= limit or curNorm > maxNorm:
            return None
        it.append(iters)
        norms.append(curNorm)
    return x
Пример #2
0
def seidel(a, b, coeff=1.0, eps=1e-10, limit=1000):
    if not checkSize(a, b):
        raise Exception("Invalid operands")
    a = deepcopy(a)
    b = deepcopy(b)
    n = shape(a)[0]
    for i in range(n):
        if a[i, i] == 0:
            raise Exception("Powerless method")
        b[i] /= a[i, i]
        a[i] /= a[i, i]
    x = zeroTerm(n)
    iters = 0
    maxNorm = 1e100 * n
    while norm(a * x - b) > eps:
        nextX = deepcopy(x)
        for i in range(n):
            nextX[i] -= a[i] * nextX - b[i]
        x += coeff * (nextX - x)
        iters += 1
        curNorm = norm(a * x - b)
        if iters >= limit or curNorm > maxNorm:
            return None
        it.append(iters)
        norms.append(curNorm)
    return x
Пример #3
0
def gradient(a, b, eps = 1e-10, limit = 1000):
    a = deepcopy(a)
    b = deepcopy(b)
    if not checkSize(a, b):
        raise Exception("Invalid operands")
    n = shape(a)[0]
    x = zeroTerm(n)
    r1 = b - a * x
    r2 = b - a.transpose() * x
    p1 = r1
    p2 = r2
    x0 = matrix([[inf]] * n)
    iters = 0
    maxNorm = 1e100 * n
    while norm(r1) > eps:
        koef = (r2.transpose() * r1).item(0) / (p2.transpose() * (a * p1)).item(0)
        x0 = x
        x = x0 + koef * p1
        r1_new = r1 - koef * a * p1
        r2_new = r2 - koef * a.transpose() * p2
        beta = (r2_new.transpose() * r1_new).item(0) / (r2.transpose() * r1).item(0)
        r1 = r1_new
        r2 = r2_new
        p1 = r1 + beta * p1
        p2 = r2 + beta * p2
        iters += 1
        curNorm = norm(r1)
        if iters >= limit or curNorm > maxNorm:
            return None
        it.append(iters)
        norms.append(curNorm)
    return x
Пример #4
0
def gauss(a, b, eps=0):
    a = deepcopy(a)
    b = deepcopy(b)
    if not checkSize(a, b):
        raise Exception("Invalid operands")
    n = shape(a)[0]
    for i in range(n):
        for j in range(i, n):
            if abs(a[i, j]) > eps:
                a[i], a[j] = copy(a[j]), copy(a[i])
                b[i], b[j] = copy(b[j]), copy(b[i])
                b[i] /= a[i, i]
                a[i] /= a[i, i]
                for k in range(n):
                    if k != i:
                        b[k] -= a[k, i] * b[i]
                        a[k] -= a[k, i] * a[i]
                break
    for i in range(n):
        if abs(a[i, i]) <= eps and abs(b[i, 0]) > eps:
            return 0, None
    for i in range(n):
        if abs(a[i, i]) <= eps:
            return inf, None
    return 1, matrix([[b[i, 0] / a[i, i]] for i in range(n)])
 def menuCreateContainer(self):
     container_menu = [
         inquirer.Text('name',
                       message="Write the name of the container",
                       ),
         inquirer.Text('duration',
                       message="Define the duration of the trimmed video as mm:ss knowing that the maximun is 10:35",
                       ),
         inquirer.Text('size',
                       message="Define the width and height as (360x240) or the resolution as (720p)",
                       ),
         inquirer.List('video_codec',
                       message="Choose a video code among the following options",
                       choices=['mpeg2video', 'h264'],
                       ),
         inquirer.List('audio_codec',
                       message="Choose an audio code among the following options",
                       choices=['aac', 'mp3', 'ac3'],
                       ),
         inquirer.Text('bitrate',
                       message="Define the bitrate of the audio",
                       ),
     ]
     result = inquirer.prompt(container_menu)
     if (checkDuration(result['duration']) and checkSize(result['size'])):
         return result
     return None