Wie kann ich Vektor aufrecht darstellen?

Fragen zu Tkinter.
Antworten
Brando
User
Beiträge: 171
Registriert: Donnerstag 28. Januar 2016, 15:36

Gerne würde ich einen Vektor, den ich mit np.array gebildet habe so darstellen, dass er aufrecht steht, und die Klammerung die drei Werte des Vektors übergreifend darstellt. Wie kann ich das durch bspw. Interaktion mit Latex?
Brando
User
Beiträge: 171
Registriert: Donnerstag 28. Januar 2016, 15:36

ausserhalb von tkinter erreiche ich das durch folgenden Code:

Code: Alles auswählen

from sympy.matrices import *
from sympy.printing import *
from IPython.display import display, HTML, Math, Latex, clear_output
from ipywidgets import widgets
from random import randint

text1 = widgets.Text()

button1 = widgets.Button(description="Auswerten")
button2 = widgets.Button(description="Neue Aufgabe")

x = Matrix()
y = Matrix()

latexWidget = widgets.Latex()

taskWidget = widgets.HTML()
taskWidget.value = "<b>Berechnen Sie:</b>"

mhbox1 = widgets.HBox((taskWidget, latexWidget))
mhbox2 = widgets.HBox((button1, button2))

def init_vectors(b):
        global x, y, text1
        x = Matrix([randint(-20,20), randint(-20,20), randint(-20,20)])
        y = Matrix([randint(-20,20), randint(-20,20), randint(-20,20)])
        text1.value = ""
        display_task()

def display_task():
        global x, y, latexWidget

        clear_output()

        a1 = latex(x)
        a2 = latex(y)

        a1 = a1.replace("left[", "left(")
        a2 = a2.replace("left[", "left(")
        a1 = a1.replace("right]", "right)")
        a2 = a2.replace("right]", "right)")

        str1 = "$\langle" + a1 + ", " + a2 + "\\rangle$"
        latexWidget.value = str1

def evaluate(b):
        global x, y, text1
        z = x.dot(y)

        clear_output()
        display_task()

        if "{0}".format(z) == text1.value:
                display(HTML("<b><font color='green'>Richtig</font></b>"))
        else:
                display(HTML("<b><font color='red'>Falsch</font></b>"))


def exec_la_scalar():
        init_vectors(button2)
        button2.on_click(init_vectors)
        button1.on_click(evaluate)
        display(widgets.VBox((mhbox1, text1, mhbox2)))

Antworten