Method on @sym: char (x)

Return string representation of a symbolic expression.

Example:

f = [sym(pi)/2 ceil(sym('x')/3); sym('alpha') sym(3)/2]
  ⇒ f = (sym 2×2 matrix)

      ⎡π  ⎡x⎤⎤
      ⎢─  ⎢─⎥⎥
      ⎢2  ⎢3⎥⎥
      ⎢      ⎥
      ⎣α  3/2⎦

char(f)
  ⇒ Matrix([[pi/2, ceiling(x/3)], [alpha, 3/2]])

This command generally gives a human-readable string but it may not be sufficient for perfect reconstruction of the symbolic expression. For example char(x) does not display assumptions:

syms x positive
char (x)
  ⇒ x

And because of this, passing the output of char to sym loses information:

x2 = sym (char (x));

assumptions (x2)
  ⇒ ans =
      {}(0x0)

If you need a more precise string representation of a symbolic object, the underlying SymPy string representation (“srepr”) can be found using sympy:

sympy (x)
  ⇒ ans = Symbol('x', positive=True)

See also: @sym/disp, @sym/pretty, @sym/sympy, sym.

Package: symbolic