diff --git a/roman_schenk_S1_Aufg2.py b/roman_schenk_S1_Aufg2.py index 789226b..59945bd 100644 --- a/roman_schenk_S1_Aufg2.py +++ b/roman_schenk_S1_Aufg2.py @@ -20,21 +20,35 @@ def polynom_function(coefficients, x): 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(xmin, xmax, xsteps): +def plot_derivative_f(coefficients, xmin, xmax, xsteps): x = np.arange(xmin, xmax + xsteps, xsteps) - f = np.array(polynom_function(x)) + f = np.array(polynom_function(derivative_f(coefficients), x)) plt.plot(x, f) plotLegend.append('f\'(x)') -def plot_integral_f(xmin, xmax, xsteps): +def plot_integral_f(coefficients, xmin, xmax, xsteps): x = np.arange(xmin, xmax + xsteps, xsteps) - f = np.array(polynom_function(x)) + f = np.array(polynom_function(integral_f(coefficients), x)) plt.plot(x, f) plotLegend.append('F(x)') @@ -42,6 +56,6 @@ 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(xmin, xmax, xsteps) - #plot_integral_f(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) \ No newline at end of file