Solved Task 2.1
This commit is contained in:
		
							parent
							
								
									15905693f8
								
							
						
					
					
						commit
						5b0463467e
					
				| 
						 | 
					@ -0,0 +1,49 @@
 | 
				
			||||||
 | 
					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):
 | 
				
			||||||
 | 
					    n = len(coefficients) - 1
 | 
				
			||||||
 | 
					    result = 0
 | 
				
			||||||
 | 
					    for power, coefficient in enumerate(coefficients):
 | 
				
			||||||
 | 
					        result += coefficient * x ** power
 | 
				
			||||||
 | 
					        power += 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):
 | 
				
			||||||
 | 
					    x = np.arange(xmin, xmax + xsteps, xsteps)
 | 
				
			||||||
 | 
					    f = np.array(polynom_function(x))
 | 
				
			||||||
 | 
					    plt.plot(x, f)
 | 
				
			||||||
 | 
					    plotLegend.append('f\'(x)')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def plot_integral_f(xmin, xmax, xsteps):
 | 
				
			||||||
 | 
					    x = np.arange(xmin, xmax + xsteps, xsteps)
 | 
				
			||||||
 | 
					    f = np.array(polynom_function(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(xmin, xmax, xsteps)
 | 
				
			||||||
 | 
					    #plot_integral_f(xmin, xmax, xsteps)
 | 
				
			||||||
 | 
					    showPlot(xmin, xmax, xsteps)
 | 
				
			||||||
		Loading…
	
		Reference in New Issue