2022-09-24 20:18:08 +02:00
|
|
|
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
|
|
|
|
|
2022-09-25 11:38:20 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2022-09-24 20:18:08 +02:00
|
|
|
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)')
|
|
|
|
|
2022-09-25 11:38:20 +02:00
|
|
|
def plot_derivative_f(coefficients, xmin, xmax, xsteps):
|
2022-09-24 20:18:08 +02:00
|
|
|
x = np.arange(xmin, xmax + xsteps, xsteps)
|
2022-09-25 11:38:20 +02:00
|
|
|
f = np.array(polynom_function(derivative_f(coefficients), x))
|
2022-09-24 20:18:08 +02:00
|
|
|
plt.plot(x, f)
|
|
|
|
plotLegend.append('f\'(x)')
|
|
|
|
|
2022-09-25 11:38:20 +02:00
|
|
|
def plot_integral_f(coefficients, xmin, xmax, xsteps):
|
2022-09-24 20:18:08 +02:00
|
|
|
x = np.arange(xmin, xmax + xsteps, xsteps)
|
2022-09-25 11:38:20 +02:00
|
|
|
f = np.array(polynom_function(integral_f(coefficients), x))
|
2022-09-24 20:18:08 +02:00
|
|
|
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)
|
2022-09-25 11:38:20 +02:00
|
|
|
plot_derivative_f(coefficients_task_1, xmin, xmax, xsteps)
|
|
|
|
plot_integral_f(coefficients_task_1, xmin, xmax, xsteps)
|
2022-09-24 20:18:08 +02:00
|
|
|
showPlot(xmin, xmax, xsteps)
|