Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.7 kB
4
Indexable
from cgitb import text
from pkgutil import get_data
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(KoordinateX, KoordinateY):
    
    print(KoordinateX, KoordinateY)
    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(KoordinateX), float(KoordinateY), 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(4))

KoordinateY.on_submit(submit(KoordinateX.text, KoordinateY.text))



plt.show()