pythonlatexsympysymbolic-math

Creating particular symbol \tilde{x} in SymPy


I am using Pythons SymPy and am struggling to create a particular variable. Particularly $\tilde{x}$.

I know that I can place a hat on top of a variable in this fashion

import sympy as sym
from sympy import *

xhat= sym.symbols("\hat{x} ")
xhat

but it is not working for the tilde.

Attempt 1

xtilde, ytilde =  symbols("\tilde{x} \tilde{y}) ") # Create
xtilde # Print variable

ildex

Attempt 2

xtilde, ytilde =  symbols("\sim{x} \sim{y}) ") # Create
xtilde # Print variable

~x

Attempt 3

xtilde, ytilde =  symbols("\~{x} \~{y}) ") # Create
xtilde # Print variable

\~x

How does one add tilde on top of the variable in Sympy?


Solution

  • You can try this:

    import sympy as sym
    
    from sympy import *
    
    sym.init_printing()
    
    xtilde= sym.symbols("xtilde ")
    
    xtilde