| | |
| | | class Polynomial: |
| | | def __init__(self, *argv: float): |
| | | self.__coefficients = [] |
| | | for c in argv: |
| | | self.__coefficients.append(c) |
| | | self.__coefficients = tuple(argv) |
| | | |
| | | def __repr__(self) -> str: |
| | | coe = [] |
| | | for c in self.__coefficients: |
| | | coe.append(f'{c}') |
| | | return ' '.join(coe) |
| | | |
| | | def __str__(self): |
| | | return self.__repr__() |
| | | |
| | | def evaluate(self, x: float) -> tuple[float, list[float]]: |
| | | p = self.__coefficients[-1] |
| | |
| | | for ak in self.__coefficients[-2::-1]: |
| | | p = ak + (p * x) |
| | | c.insert(0, p) |
| | | return c[0], c[1:] |
| | | return c[0], c[1:] |
| | | |
| | | def __repr__(self) -> str: |
| | | coe = [] |
| | | for c in self.__coefficients: |
| | | coe.append(f'{c}') |
| | | return ' '.join(coe) |