Exemple #1
0
def newton(poli, a, b):
    segments = segmentation.segmentationPoli(poli, a, b)

    roots = []
    dpoli = polinom.d(poli)

    global newLog
    newLog = []

    for i in range(len(segments)):
        log = [[]]
        x = segments[i]
        nextx = x - 1
        while abs(x - nextx) >= ANS_EPSILON:
            dfx = polinom.polinomValue(dpoli, x)
            fx = polinom.polinomValue(poli, x)

            nextx = x - fx / dfx

            log.append([abs(x - nextx), nextx, fx])

            nextx, x = x, nextx

        if len(roots) > 0:
            if abs(roots[-1] - x) < EPSILON:
                continue

        roots.append(x)
        newLog += log

    return roots
Exemple #2
0
def dichotomy(polignom, a, b):
    global dihLog
    dihLog = []
    points = segmentation.segmentationPoli(polignom,a,b);

    roots = [];
    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