[Python] Avoid transformations in sympy latex printing (don't want automatic transformation of...

Discussão em 'Python' iniciado por Stack, Abril 16, 2025.

  1. Stack

    Stack Membro Participativo

    With the code:

    from sympy import *
    x = symbols('x')
    y = 1/(sqrt(2))*cos(x)
    print_latex(y)


    I obtain:

    \frac{\sqrt{2} \cos{\left(x \right)}}{2}

    [​IMG]

    I need to obtain:

    \frac{1}{\sqrt{2}}\cos{\left(x \right)}

    [​IMG]

    How to instruct print_latex to keep the original form?

    I tryed with :

    yy = Mul(1/(sqrt(2)),cos(x),evaluate=False)
    print_latex(yy)


    It gives: \frac{\sqrt{2}}{2} \cos{\left(x \right)}

    [​IMG]

    It's better, but not exactly what I want.

    With yy = Mul(cancel(1/(sqrt(2))),cos(x),evaluate=False), I obtain the same output.

    Continue reading...

Compartilhe esta Página