# Add Subscripts, Superscripts, and Accents to Symbolic Variables in the Live Editor

Starting in R2019a, MATLAB® Live Editor displays symbolic variables with subscripts, superscripts, and accents in standard mathematical notation. This example shows how to add subscripts, superscripts, and accents to symbolic variables in the MATLAB Live Editor.

To add subscripts to symbolic variables in live scripts, append the corresponding index to the variable using one underscore (`_`). For example, create two symbolic variables with subscripts using `syms`. Use these variables in an expression.

```syms F_a F_b Ftot = F_a + F_b```
`Ftot = ${F}_{a}+{F}_{b}$`

You can also use `sym` to create a symbolic variable with a subscript and assign the variable to a symbolic expression.

`Fa = sym("F_a")`
`Fa = ${F}_{a}$`

To add superscripts to symbolic variables, append the corresponding index to the variable using two underscores (`__`). For example, create two symbolic variables with superscripts.

```syms F__a F__b Ftot = F__a + F__b```
`Ftot = ${F}^{a}+{F}^{b}$`

When you assign symbolic variables to an expression, the symbolic expression is displayed in ASCII format.

To add accents to symbolic variables in live scripts, append the corresponding suffix to the variable using an underscore (`_`). For example, create symbolic variables with one dot and two dots over the symbol $\mathit{x}$. Use these variables in an equation.

```syms x x_dot x_ddot c m k eq1 = m*x_ddot - c*x_dot + k*x == 0```
`eq1 = $k x-c \stackrel{˙}{x}+m \stackrel{¨}{x}=0$`

When you compute the complex conjugate of a symbolic variable with an accent, a bar notation is added above the variable. For example, find the complex conjugate of `x_dot` using the `conj` function.

`xConj = conj(x_dot)`
`xConj = $\stackrel{‾}{\stackrel{˙}{x}}$`

This accent list shows the supported accent suffixes and the corresponding display output. The dagger accent with $†$ symbol is available since R2022b and the degree accent with ° symbol is available since R2023a.

```suffix = ["ast"; "dag"; "deg"; "hat"; "tilde"; ... "vec"; "bar"; "ubar"; "dot"; "ddot"; "tdot"; ... "qdot"; "prime"; "dprime"; "tprime"; "qprime"]; accentList = [suffix, sym("x_" + suffix)]```
```accentList =  $\left(\begin{array}{cc}\mathrm{ast}& {x}^{*}\\ \mathrm{dag}& {x}^{†}\\ \mathrm{deg}& x°\\ \mathrm{hat}& \stackrel{ˆ}{x}\\ \mathrm{tilde}& \stackrel{\sim }{x}\\ \mathrm{vec}& \stackrel{\to }{x}\\ \mathrm{bar}& \stackrel{‾}{x}\\ \mathrm{ubar}& \underset{‾}{x}\\ \mathrm{dot}& \stackrel{˙}{x}\\ \mathrm{ddot}& \stackrel{¨}{x}\\ \mathrm{tdot}& \stackrel{⃛}{x}\\ \mathrm{qdot}& \stackrel{⃜}{x}\\ \mathrm{prime}& {x}^{\prime }\\ \mathrm{dprime}& {x}^{\prime \prime }\\ \mathrm{tprime}& {x}^{\prime \prime \prime }\\ \mathrm{qprime}& {x}^{\prime \prime \prime \prime }\end{array}\right)$```

When you compute the complex conjugate transpose of a matrix containing symbolic variables, a bar notation is also added above each variable. For example, find the complex conjugate transpose of the symbolic variables in `accentList(:,2)` using the `ctranspose` or `'` function.

`conjVar = accentList(:,2)'`
```conjVar =  $\left(\begin{array}{cccccccccccccccc}\stackrel{‾}{{x}^{*}}& \stackrel{‾}{{x}^{†}}& \stackrel{‾}{x°}& \stackrel{‾}{\stackrel{ˆ}{x}}& \stackrel{‾}{\stackrel{\sim }{x}}& \stackrel{‾}{\stackrel{\to }{x}}& \stackrel{‾}{\stackrel{‾}{x}}& \stackrel{‾}{\underset{‾}{x}}& \stackrel{‾}{\stackrel{˙}{x}}& \stackrel{‾}{\stackrel{¨}{x}}& \stackrel{‾}{\stackrel{⃛}{x}}& \stackrel{‾}{\stackrel{⃜}{x}}& \stackrel{‾}{{x}^{\prime }}& \stackrel{‾}{{x}^{\prime \prime }}& \stackrel{‾}{{x}^{\prime \prime \prime }}& \stackrel{‾}{{x}^{\prime \prime \prime \prime }}\end{array}\right)$```

When you compute the nonconjugate transpose of a matrix containing symbolic variables, the display output is unchanged. For example, find the nonconjugate transpose of the symbolic variables in `accentList(:,2)` using the `transpose` or `.'` function.

`nonconjVar = accentList(:,2).'`
```nonconjVar =  $\left(\begin{array}{cccccccccccccccc}{x}^{*}& {x}^{†}& x°& \stackrel{ˆ}{x}& \stackrel{\sim }{x}& \stackrel{\to }{x}& \stackrel{‾}{x}& \underset{‾}{x}& \stackrel{˙}{x}& \stackrel{¨}{x}& \stackrel{⃛}{x}& \stackrel{⃜}{x}& {x}^{\prime }& {x}^{\prime \prime }& {x}^{\prime \prime \prime }& {x}^{\prime \prime \prime \prime }\end{array}\right)$```

### Add Multiple Subscripts, Superscripts, and Accents

You can create symbolic variables with multiple subscripts, superscripts, and accents. The multiple suffixes are assigned to the symbolic variables from left to right.

Create symbolic variables with multiple subscripts and superscripts. If you add multiple subscripts and superscripts, then the input indices are separated with a comma and displayed from left to right.

`x1 = sym("x_b_1__a__1")`
`x1 = ${x}_{b,1}^{a,1}$`
`x2 = sym("x__b_1_a__1")`
`x2 = ${x}_{1,a}^{b,1}$`

Now create symbolic variables with multiple accents. If you add multiple accents, then the input accents are assigned from left to right to the closest preceding variable or index.

`v1 = sym("v_prime_vec")`
```v1 =  $\stackrel{\to }{{v}^{\prime }}$```
`v2 = sym("v_vec_prime")`
`v2 = ${\stackrel{\to }{v}}^{\prime }$`
`va = sym("v__a_bar_prime")`
`va = ${v}^{{\stackrel{‾}{a}}^{\prime }}$`
`vb = sym("v_bar__b_prime")`
`vb = ${\stackrel{‾}{v}}^{{b}^{\prime }}$`

Adding suffixes to symbolic variables can produce similar output. However, the variables are equal only if their suffixes are also in the same order. For example, create three symbolic variables that produce similar output.

```syms F_t__a F1 = F_t__a```
`F1 = ${F}_{t}^{a}$`
`F2 = sym("F_t__a")`
`F2 = ${F}_{t}^{a}$`
`F3 = sym("F__a_t")`
`F3 = ${F}_{t}^{a}$`

Determine if the symbolic variables are equal to each other using the `isequal` function.

`tf_12 = isequal(F1,F2)`
```tf_12 = logical 1 ```
`tf_23 = isequal(F2,F3)`
```tf_23 = logical 0 ```

### Add Signs to Subscripts and Superscripts

Starting in R2022b, you can also add signs as suffixes when creating symbolic variables. The supported signs are $-$, $+$, $±$, and $\mathit{#}$. This sign list shows the supported sign suffixes and the corresponding display output.

```suffix = ["minus"; "plus"; "plusmn"; "hash"]; signList = [suffix, sym("A_" + suffix)]```
```signList =  $\left(\begin{array}{cc}\mathrm{minus}& {A}_{-}\\ \mathrm{plus}& {A}_{+}\\ \mathrm{plusmn}& {A}_{±}\\ \mathrm{hash}& {A}_{#}\end{array}\right)$```

You can add these signs in combinations with other symbols when creating symbolic variables. To combine these signs with other subscripts or superscripts, you can use one underscore (`_`) or two underscores (__) with other suffixes, respectively. For example:

`A1 = sym("A_minus_x_bar")`
`A1 = ${A}_{-\stackrel{‾}{x}}$`
`A2 = sym("A__plusmn__c")`
`A2 = ${A}^{±c}$`
`A3 = sym("A_hash_123")`
`A3 = ${A}_{\mathrm{#}123}$`
`A4 = sym("A_minus_x_plus_y__r__theta")`
`A4 = ${A}_{-x,+y}^{r,\theta }$`