#!/usr/bin/env python3 from sympy import * # hier werden die Symbole, als die Variablen benannt. Fehlt eine Variable, so kann man diese hinzufügen oder eine bereits bekannte nutzen x, y, z, a, b, c, u, v, m, n = symbols('x y z a b c u v m n') # Um die Ausgabe etwas schöner zu machen init_printing(use_unicode=True) # Man übergibt die Funktion als funktion und den Namen, den sie in der Ausgabe erhalten soll # als Ergebnis erhält man eine Ausdruck, der sich direkt per Copy&Paste in Libreoffice als Formel einfügen lässt def get_odt_of(funktion, name): funktion= mathematica_code(simplify(funktion)) funktion= funktion.replace("*", " cdot ") funktion= funktion.replace(".", ",") funktion= funktion.replace(",0", "") funktion= funktion.replace("Log", "log") funktion= funktion.replace("[", "(") funktion= funktion.replace("]", ")") funktion= funktion.replace("{", "") funktion= funktion.replace("}", "") funktion= funktion.replace("/", "over") print ( name+"(x)=", funktion) return funktion # Man übergibt die Funktion als funktion und den Namen, den sie in der Ausgabe erhalten soll # als Ergebnis erhält man eine Ausdruck, der sich direkt per Copy&Paste in Geobra als Formel einfügen lässt def get_geogebra_of(funktion, name): funktion= mathematica_code(simplify(funktion)) funktion= funktion.replace(".0", "") funktion= funktion.replace("Log", "log") funktion= funktion.replace("[", "(") funktion= funktion.replace("]", ")") funktion= funktion.replace("{", "") funktion= funktion.replace("}", "") print ( name+"(x)=", funktion) return funktion # Beispiel: Der Ausdruck q soll ausgeklammert werden q=(3*a - 5*b) *(6*x - 7*y + 9*z) - (5*x-8*y +8*z)*(4*a-5*b) get_odt_of(sympify(q), "q")