Solved Task 1

This commit is contained in:
schrom01 2022-09-24 19:55:14 +02:00
parent 8f9a14e0ab
commit 15905693f8
1 changed files with 40 additions and 7 deletions

View File

@ -1,17 +1,50 @@
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
def fun_f(x): xmin, xmax, xsteps = -10, 10, 0.1
return x ** 5 - 5 * x ** 4 - 30 * x ** 3 + 110 * x ** 2 + 29 * x - 105 plotLegend = []
def plot_f(xmin, xmax, xsteps): def showPlot():
x = np.arange(xmin, xmax + xsteps, xsteps)
f = np.array(fun_f(x))
plt.plot(x, f)
plt.xlim(-11, 11) plt.xlim(-11, 11)
plt.xticks(np.arange(xmin, xmax + xsteps, 1.0)) plt.xticks(np.arange(xmin, xmax + xsteps, 1.0))
plt.xlabel("x")
plt.ylim(-1300, 1300) plt.ylim(-1300, 1300)
plt.ylabel("y")
plt.grid(markevery=1) plt.grid(markevery=1)
plt.legend(plotLegend)
plt.title("Aufgabe 1")
plt.show() plt.show()
#plot_f(-10, 10, 0.1) 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()