示例#1
0
        def setup_pprint():
            from sympy import pprint_use_unicode
            # force pprint to be in ascii mode in doctests
            pprint_use_unicode(False)

            # hook our nice, hash-stable strprinter
            from sympy.interactive import init_printing
            from sympy.printing import sstrrepr
            init_printing(sstrrepr)
示例#2
0
def setup_pprint():
    from sympy import pprint_use_unicode
    # force pprint to be in ascii mode in doctests
    pprint_use_unicode(False)

    # hook our nice, hash-stable strprinter
    from sympy.interactive import init_printing
    from sympy.printing import sstrrepr
    init_printing(sstrrepr)
示例#3
0
from sympy import pretty_print, Eq, solve, symbols
from sympy.interactive import init_printing

init_printing()

g = 9.8
P = 0.025 * g
k = 15.3
m = 0.050
h = 0.09

delta_x = symbols('delta_x')
eq = Eq(m**2 / (P + m * g) * g * h, -m * delta_x + k / (2 * g) * delta_x**2)
pretty_print(eq)
solution = solve(eq, delta_x)
pretty_print(solution)

delta_x = solution[1]
result = h + delta_x
print("result is {0:.1f} cm".format(result * 100))
示例#4
0
from sympy import *
from sympy.printing.latex import LatexPrinter

def disp_latex(expr, **settings):
    return LatexPrinter(settings).doprint(expr).replace('$$', '$$\displaystyle', 1)

from sympy.interactive import init_printing
init_printing(use_latex="mathjax",latex_mode="equation",itex=True,latex_printer=disp_latex)
    
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"

# try:
#     def exit_register(fun, *args, **kwargs):
#         """ Decorator that registers at post_execute. After its execution it
#         unregisters itself for subsequent runs. """
#         def callback():
#             fun()
#             ip.events.unregister('post_execute', callback)
#         ip.events.register('post_execute', callback)


#     ip = get_ipython()
# except NameError:
#     from atexit import register as exit_register


# @exit_register
# def callback():
#     print('I\'m done!')
示例#5
0
import re
import math
import sympy as sy
from sympy import *
from sympy.interactive import init_printing
init_printing(pretty_print=True)

def calculate(equation: str) -> str:
    print("Equação: ", equation)

    x, y, z = sy.symbols('x y z')

    if 'Limit x->' in equation:
        f = Lambda(x, equation[14:-1])
        print("equation[9:11]: ", equation[9:11])
        print("str(equation[11]): ", str(equation[11]))
        successfully_solved_equation = limit(f(x), x, equation[9:11], str(equation[11]))

    if 'Derivar' in equation:
        if "f'(" in equation:
            f = Lambda(x, equation[16:-1])
            f1 = Lambda(x, diff(f(x),x))
            successfully_solved_equation = f1(int(equation[11:12]))
        elif "f(" in equation:
            f = Lambda(x, equation[15:-1])
            successfully_solved_equation = sy.diff(f(x), x)

    if 'Integrar' in equation:
        if "f(x) (" in equation:
            f = Lambda(x, equation[25:-1])
            print("f: ", f)
示例#6
0
from sympy.interactive import init_printing
from sympy import Symbol, sqrt
from sympy.abc import x, y
sqrt(21)
init_printing(pretty_print=True)
sqrt(21)
theta = Symbol('theta')
init_printing(use_unicode=True)
theta
init_printing(use_unicode=False)
theta
init_printing(order='lex')
str(2 * y + 3 * x + 2 * y**2 + x**2 + 1)
init_printing(order='grlex')
str(2 * y + 3 * x + 2 * y**2 + x**2 + 1)
init_printing(order='grevlex')
str(2 * y * x**2 + 3 * x * y**2)
init_printing(order='old')
str(2 * y + 3 * x + 2 * y**2 + x**2 + 1)
init_printing(num_columns=10)
str(2 * y + 3 * x + 2 * y**2 + x**2 + 1)