Hong-Phuc Bui
10 days ago fd66402c90a63cf8ce455c3614b9160884f74c61
polymonial/polynomial.py
@@ -1,3 +1,6 @@
#from turtle import Turtle
import turtle
class Polynomial:
    def __init__(self, *argv: float):
        if len(argv) < 1:
@@ -47,4 +50,26 @@
            coe.append(f'{c}')
        return ' '.join(coe)
def plot_polynomial(t:turtle.Turtle, p:Polynomial, width=500, height=500):
    x_value = []
    y_value = []
    n = 9
    delta = 2 * width / (n-1)
    x0 = -width
    for i in range(0, n):
        y0 = p.evaluate(x0)[0]
        x_value.append(x0)
        y_value.append(y0)
        print(x0, y0)
        x0 = x0 + delta
    y_min = min(y_value)
    y_max = max(y_value)
    m = height - (2*height)/(y_max - y_min) * y_max
    w = lambda y : 2*height/(y_max - y_min) * y + m
    for i in range(0, n):
        x = x_value[i]
        y = y_value[i]
        y = w(y)
        print(x,y)
        t.goto(x,y)
    pass