From 15905693f88955e2d334c078922ac65e33dfe2a0 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Sat, 24 Sep 2022 19:55:14 +0200 Subject: [PATCH] Solved Task 1 --- roman_schenk_S1_Aufg1.py | 47 ++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/roman_schenk_S1_Aufg1.py b/roman_schenk_S1_Aufg1.py index d3ad7cf..02c3eb7 100644 --- a/roman_schenk_S1_Aufg1.py +++ b/roman_schenk_S1_Aufg1.py @@ -1,17 +1,50 @@ import numpy as np import matplotlib.pyplot as plt -def fun_f(x): - return x ** 5 - 5 * x ** 4 - 30 * x ** 3 + 110 * x ** 2 + 29 * x - 105 +xmin, xmax, xsteps = -10, 10, 0.1 +plotLegend = [] -def plot_f(xmin, xmax, xsteps): - x = np.arange(xmin, xmax + xsteps, xsteps) - f = np.array(fun_f(x)) - plt.plot(x, f) +def showPlot(): 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 1") plt.show() -#plot_f(-10, 10, 0.1) \ No newline at end of file +def function_f(x): + return x ** 5 - 5 * x ** 4 - 30 * x ** 3 + 110 * x ** 2 + 29 * x - 105 + +def derivative_f(x): + return 5 * x ** 4 - 20 * x ** 3 - 90 * x ** 2 + 220 * x + 29 + +def integral_f(x): + c = 0 + return (1/6) * x ** 6 - x ** 5 - (30/4) * x ** 4 + (110/3) * x ** 3 + (29/2) * x ** 2 - 105 * x + c + +def plot_function_f(): + x = np.arange(xmin, xmax + xsteps, xsteps) + f = np.array(function_f(x)) + plt.plot(x, f) + plotLegend.append('f(x)') + +def plot_derivative_f(): + x = np.arange(xmin, xmax + xsteps, xsteps) + f = np.array(derivative_f(x)) + plt.plot(x, f) + plotLegend.append('f\'(x)') + +def plot_integral_f(): + x = np.arange(xmin, xmax + xsteps, xsteps) + f = np.array(integral_f(x)) + plt.plot(x, f) + plotLegend.append('F(x)') + +if __name__ == "__main__": + plot_function_f() + plot_derivative_f() + plot_integral_f() + showPlot() \ No newline at end of file