import numpy as np import matplotlib.pyplot as plt plotLegend = [] def showPlot(xmin, xmax, xsteps): plt.xlim(-11, 11) plt.xticks(np.arange(xmin, xmax + xsteps, 1.0)) plt.xlabel("x") plt.ylim(-1300, 1300) plt.ylabel("y") plt.grid(markevery=1) plt.legend(plotLegend) plt.title("Aufgabe 2") plt.show() def polynom_function(coefficients, x): result = 0 for power, coefficient in enumerate(coefficients): result += coefficient * x ** power return result def derivative_f(coefficients): result = [] for i in range(1, len(coefficients)): result.append(coefficients[i] * i) return result def integral_f(coefficients): c = 0 result = [c] for i in range(0, len(coefficients)): result.append(coefficients[i] / (i+1)) return result def plot_polynom_function(coefficients, xmin, xmax, xsteps): x = np.arange(xmin, xmax + xsteps, xsteps) f = np.array(polynom_function(coefficients, x)) plt.plot(x, f) plotLegend.append('f(x)') def plot_derivative_f(coefficients, xmin, xmax, xsteps): x = np.arange(xmin, xmax + xsteps, xsteps) f = np.array(polynom_function(derivative_f(coefficients), x)) plt.plot(x, f) plotLegend.append('f\'(x)') def plot_integral_f(coefficients, xmin, xmax, xsteps): x = np.arange(xmin, xmax + xsteps, xsteps) f = np.array(polynom_function(integral_f(coefficients), x)) plt.plot(x, f) plotLegend.append('F(x)') if __name__ == "__main__": xmin, xmax, xsteps = -10, 10, 0.1 coefficients_task_1 = [-105, 29, 110, -30, -5, 1] plot_polynom_function(coefficients_task_1, xmin, xmax, xsteps) plot_derivative_f(coefficients_task_1, xmin, xmax, xsteps) plot_integral_f(coefficients_task_1, xmin, xmax, xsteps) showPlot(xmin, xmax, xsteps)