import numpy as np import matplotlib.pyplot as plt import math #Variablen und Konstanten tmax=2 dt=0.01 #10 ms g=9.81 l=1.45 # m tau=math.sqrt(2*l/(3*g)) vPhi0=0 #zero initial phi-velocity phi0=0.25 t=[] phi=[] vPhi=[] # initial values phi.append(phi0) vPhi.append(vPhi0) i=0 #Explizites Euler Verfahren/ Iteration while True: vPhi.append(vPhi[i] +dt*math.sin(phi[i])/(tau**2)) phi.append(phi[i]+dt*vPhi[i]) i+=1 if phi[i] >= math.pi/2: break # Berechnung Auftreffzeitpunkt tmax=len(phi)*dt print(tmax) #erzeuge Zeiten t=np.arange(0,tmax,dt) # Erzeuge eine Figure. fig = plt.figure(figsize=(9, 4)) fig.set_tight_layout(True) # Plotte das Winkel-Zeit-Diagramm. ax1 = fig.add_subplot(1, 1, 1) ax1.set_xlabel("t [s]") ax1.set_ylabel("phi [rad]") ax1.grid() #ax1.plot(t, vPhi, ".b", label="Vphi") ax1.plot(t, phi, ".r", label="Phi") ax1.legend() plt.show()