# Untitled

unknown
plain_text
a year ago
2.1 kB
2
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

import tkinter as tk
import matplotlib

matplotlib.use('TkAgg')

from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import (
FigureCanvasTkAgg,
)

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([3,3,2])
Q = 1
a = 1

class Sim:
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 = [x0, y0, 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

# create the barchart
ax.plot(aa, bb, cc)
ax.set_xlabel('X-Koordinate')
ax.set_ylabel('Y-Koordinate')
ax.set_zlabel('Z-Koordinate')

class App(tk.Tk):
def __init__(self):
super().__init__()

self.title('Tkinter Matplotlib Demo')

# create a figure
figure = Figure(figsize=(6, 4), dpi=100)

# create FigureCanvasTkAgg object
figure_canvas = FigureCanvasTkAgg(figure, self)

# create the toolbar