| | |
| | | #from turtle import Turtle |
| | | import turtle |
| | | |
| | | class Polynomial: |
| | | def __init__(self, *argv: float): |
| | | if len(argv) < 1: |
| | |
| | | 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 |