Пример #1
0
        if len(roots) > 0:
            if abs(roots[-1] - x) < EPSILON:
                continue

        roots.append(x)
        newLog += log

    return roots


def printNewLog():
    if len(newLog) == 0:
        print("newLog is empty")
        return

    i = 0
    for l in newLog:
        if len(l) == 3:
            i += 1
            print("{0:2} | {1[0]: .10f} | {1[1]: .10f} | {1[2]: .10f}".format(i, l))
        else:
            i = 0
            print("\nIt | {0:13} | {1:13} | {2:13}".format("dXn", "Xn", "f(Xn)"))
    return


if __name__ == "__main__":
    print(newton(polinom.formPolinom([1.0, -1.0, 2.0, math.pi, math.e]), -4.23423425, 3.265621616))
    printNewLog()
Пример #2
0
    for i in range(len(points)-1):
        x, y = points[i],points[i+1]
        dihLog.append([]);
        p = binsearch(x,y)
        if len(roots)==0:
            roots.append(p)
        elif abs(roots[-1]-p)>=EPSILON:
            roots.append(p)

    return roots

def printDihLog():
    global dihLog
    if len(dihLog)==0:
        print("dihLog is empty")
        return
    
    i = 0
    for l in dihLog:
        if len(l)==5:
            i += 1
            print("{0:>2} | ".format(i)+"{0[0]: .10f} | {0[1]: .10f} | {0[2]: .10f} | {0[4]: 3n} | {0[3]: .10f}".format(l))
        else:
            i = 0
            print("\nIt | {0:^13} | {1:^13} | {2:^13} | {4:^3} | {3:^16}".format("L","R","Xn","f(Xn)","L/R"))
    return

if __name__ == "__main__":
    print(dichotomy(polinom.formPolinom([1.0, -1.0, 2.0, math.pi, math.e]), -4.23423425, 3.265621616))
    printDihLog()