Untitled
unknown
plain_text
2 years ago
1.7 kB
3
Indexable
Never
from scipy.integrate import solve_ivp import numpy as np import matplotlib.pyplot as plt from matplotlib.pyplot import figure from matplotlib.widgets import TextBox from matplotlib.widgets import Button ax = plt.figure().add_subplot(projection='3d') ax.set_xlabel('X-Koordinate') ax.set_ylabel('Y-Koordinate') ax.set_zlabel('Z-Koordinate') #x0 = 3 #y0 = 3 z0 = 2 vx0 = -1 vy0 = 5 vz0 = 0 t0 = 0 tf = 2 m = np.array([1,0,0]) r = np.array([0,0,0]) Q = 1 a = 1 def submit(xbox,ybox): print(xbox) def mag_bewegung(t, D, m, Q, r, a): x, vx, y, vy, z, vz = D v = np.array([vx, vy, vz]) o = np.array([x, y, z]) ra = o - r rar = np.sqrt(sum(ra*ra)) B = (3 * (np.dot(m, (ra)/rar))*((ra)/rar)-m)/rar*rar*rar s = (Q*np.cross(v,B))/a sx = s[0] sy = s[1] sz = s[2] fun = [vx, sx, vy, sy, vz, sz] return fun D0 = [float(xbox), float(ybox), z0, vx0, vy0, vz0] NumSol = solve_ivp(mag_bewegung, [t0, tf], D0, method="RK45", args=(m, Q, r, a), atol=1e-8, rtol=1e-8) aa, bb, cc, dd, ee, ff = NumSol.y t = NumSol.t aa, bb, cc, dd, ee, ff = NumSol.y #print(aa,bb) ax.plot(aa, bb, cc) plt.draw() xbox = plt.axes([0.2, 0.15, 0.8, 0.075]) ybox = plt.axes([0.2, 0.05, 0.8, 0.075]) KoordinateX = TextBox(xbox, 'X von Teilchen', initial=int(3)) KoordinateY = TextBox(ybox, 'Y von Teilchen', initial=int(3)) KoordinateX.on_submit(submit(xbox.text(),ybox.text())) KoordinateY.on_submit(submit(xbox.text(),ybox.text())) plt.show()