diff --git a/serie1/IT19ta_ZH7_S1_Aufg2.py b/serie1/IT19ta_ZH7_S1_Aufg2.py index e8b6c1f..eea2b46 100755 --- a/serie1/IT19ta_ZH7_S1_Aufg2.py +++ b/serie1/IT19ta_ZH7_S1_Aufg2.py @@ -1,4 +1,76 @@ #!/usr/bin/env python3 +import numpy +import matplotlib.pyplot as plt + + +STEPS = 1 + + +def gen_polynom(range_, coefficients, derivativ=False, integral=False): + if derivativ is True: + n = len(coefficients) - 1 + deriv_coefficients = coefficients + + for index, coefficient in enumerate(coefficients): + deriv_coefficients[index] = coefficient * n + n -= 1 + + coefficients = deriv_coefficients + n = len(coefficients) - 2 + elif integral is True: + n = len(coefficients) - 1 + integral_coefficients = coefficients + + for index, coefficient in enumerate(coefficients): + integral_coefficients[index] = coefficient * (1 / (n + 1)) + n -= 1 + + coefficients = integral_coefficients + n = len(coefficients) + else: + n = len(coefficients) - 1 + + x = range_ + for coefficient in coefficients: + print(str(coefficient) + "*" + str(x) + "**" + str(n)) + x = coefficient * range_ ** n + n -= 1 + return x + + +def calc_func(vector, xmin, xmax, derivativ=False, integral=False): + x = numpy.arange(xmin, xmax, STEPS) + y = gen_polynom(x, vector) + + plt.plot(x, y, label="f(x)") + + if derivativ is True: + y = gen_polynom(x, vector, derivativ=True) + plt.plot(x, y, label="f'(x)") + + if integral is True: + y = gen_polynom(x, vector, integral=True) + plt.plot(x, y, label="F(x)") + + +def check_values(vector, xmin, xmax): + if not vector or not xmin or not xmax: + raise Exception("Fehler") + + if len(numpy.shape(vector)) > 1: + raise Exception("Fehler") + if __name__ == "__main__": - pass + vector = [2, 1, 3] + xmin = -5 + xmax = 5 + + check_values(vector, xmin, xmax) + calc_func(vector, xmin, xmax, derivativ=True) + + plt.grid() + plt.xlabel("x") + plt.ylabel("y") + plt.legend() + plt.show()