# sympref

Set symbolic preferences

## Syntax

``oldVal = sympref(pref,value)``
``oldVal = sympref(pref)``
``oldPrefs = sympref(prefs)``
``oldPrefs = sympref()``

## Description

example

````oldVal = sympref(pref,value)` sets the symbolic preference `pref` to `value` and returns the previous value of the preference to `oldVal`. You can set the preference to its default value using `sympref(pref,'default')`.Symbolic preferences can affect the computation of the symbolic functions `fourier`, `ifourier`, and `heaviside`, and the display format of symbolic output.```

example

````oldVal = sympref(pref)` returns the current value of `pref`.```

example

````oldPrefs = sympref(prefs)` sets multiple symbolic preferences to the values in the structure `prefs` and returns the previous values of all preferences to `oldPrefs`. You can set all symbolic preferences to their default values using `sympref('default')`.```

example

````oldPrefs = sympref()` returns the current values of all symbolic preferences. NoteSymbolic preferences persist through successive MATLAB® sessions. Opening a new session does not restore the default preferences. ```

## Examples

collapse all

The Fourier transform $\mathit{F}\left(\mathit{w}\right)$ of $\mathit{f}=\mathit{f}\left(\mathit{t}\right)$ is

`$\mathit{F}\left(\mathit{w}\right)=\mathit{c}\text{\hspace{0.17em}}{\int }_{-\infty }^{\infty }\mathit{f}\left(\mathit{t}\right)\text{\hspace{0.17em}}{\mathit{e}}^{\mathit{i}\text{\hspace{0.17em}}\mathit{swt}}\text{\hspace{0.17em}}\mathit{dt},$`

where $\mathit{c}$ and $\mathit{s}$ are parameters with the default values 1 and –1, respectively. Other common values for $\mathit{c}$ are $1/\left(2\pi \right)$ and $1/\sqrt{2\pi }$, and other common values for $\mathit{s}$ are $1$, $-2\pi$, and $2\pi$.

Find the Fourier transform of `sin(t)` with default `c` and `s` parameters.

```syms t w F = fourier(sin(t),t,w)```
`F = $-\pi \left(\delta \text{dirac}\left(w-1\right)-\delta \text{dirac}\left(w+1\right)\right) \mathrm{i}$`

Find the same Fourier transform with $\mathit{c}=1/\left(2\pi \right)$ and $\mathit{s}=1$. Set the parameter values by using the `'FourierParameters'` preference. Represent $\pi$ exactly by using `sym`. Specify the values of `c` and `s` as the vector `[1/(2*sym(pi)) 1]`. Store the previous values returned by `sympref` so that you can restore them later.

`oldVal = sympref('FourierParameters',[1/(2*sym(pi)) 1])`
`oldVal = $\left(\begin{array}{cc}1& -1\end{array}\right)$`
`F = fourier(sin(t),t,w)`
```F =  $\frac{\delta \text{dirac}\left(w-1\right) \mathrm{i}}{2}-\frac{\delta \text{dirac}\left(w+1\right) \mathrm{i}}{2}$```

The preferences you set using `sympref` persist through your current and future MATLAB sessions. Restore the previous values of `c` and `s` to `oldVal`.

`sympref('FourierParameters',oldVal);`

Alternatively, you can restore the default values of `c` and `s` by specifying the `'default'` option.

`sympref('FourierParameters','default');`

In Symbolic Math Toolbox™, the default value of the Heaviside function at the origin is 1/2. Return the value of `heaviside(0)`. Find the Z-transform of `heaviside(x)` for this default value of `heaviside(0)`.

```syms x H = heaviside(sym(0))```
```H =  $\frac{1}{2}$```
`Z = ztrans(heaviside(x))`
```Z =  $\frac{1}{z-1}+\frac{1}{2}$```

Other common values for the Heaviside function at the origin are 0 and 1. Set `heaviside(0)` to `1` using the `'HeavisideAtOrigin'` preference. Store the previous value returned by `sympref` so that you can restore it later.

`oldVal = sympref('HeavisideAtOrigin',1)`
```oldVal =  $\frac{1}{2}$```

Check if the new value of `heaviside(0)` is 1. Find the Z-transform of `heaviside(x)` for this value.

`H = heaviside(sym(0))`
`H = $1$`
`Z = ztrans(heaviside(x))`
```Z =  $\frac{1}{z-1}+1$```

The new output of `heaviside(0)` modifies the output of `ztrans`.

The preferences you set using `sympref` persist through your current and future MATLAB sessions. Restore the previous value of `heaviside(0)` to `oldVal`.

`sympref('HeavisideAtOrigin',oldVal);`

Alternatively, you can restore the default value of `'HeavisideAtOrigin'` by specifying the `'default'` option.

`sympref('HeavisideAtOrigin','default');`

By default, symbolic expressions in live scripts are displayed in abbreviated output format, and typeset in mathematical notation. You can turn off abbreviated output format and typesetting using symbolic preferences.

Create a symbolic expression and return the output, which is abbreviated by default.

```syms a b c d x f = a*x^3 + b*x^2 + c*x + d; outputAbbrev = sin(f) + cos(f) + tan(f) + log(f) + 1/f```
```outputAbbrev =  ```

Turn off abbreviated output format by setting the `'AbbreviateOutput'` preference to `false`. Redisplay the expression.

```sympref('AbbreviateOutput',false); outputLong = sin(f) + cos(f) + tan(f) + log(f) + 1/f```
```outputLong =  $\mathrm{cos}\left(a {x}^{3}+b {x}^{2}+c x+d\right)+\mathrm{log}\left(a {x}^{3}+b {x}^{2}+c x+d\right)+\mathrm{sin}\left(a {x}^{3}+b {x}^{2}+c x+d\right)+\mathrm{tan}\left(a {x}^{3}+b {x}^{2}+c x+d\right)+\frac{1}{a {x}^{3}+b {x}^{2}+c x+d}$```

Create another symbolic expression and return the output, which is typeset in mathematical notation by default. Turn off rendered output and use ASCII output instead by setting the `'TypesetOutput'` preference to `false`. First, show the typeset output.

```syms a b c d x f = exp(a^b)+pi```
`f = $\pi +{\mathrm{e}}^{{a}^{b}}$`

Turn off typesetting by setting the `'TypesetOutput'` preference to `false`. Redisplay the expression.

```sympref('TypesetOutput',false); f = exp(a^b)+pi```
``` f = pi + exp(a^b) ```

The preferences you set using `sympref` persist through your current and future MATLAB sessions. Restore the default values of `'AbbreviateOutput'` and `'TypesetOutput'` by specifying the `'default'` option.

```sympref('AbbreviateOutput','default'); sympref('TypesetOutput','default');```

Display symbolic results in floating-point output format, that is the short, fixed-decimal format with 4 digits after the decimal point.

```syms x eq = x^2 - 2e3/sym(pi)*x + 0.5 == 0```
```eq =  ${x}^{2}-\frac{2000 x}{\pi }+\frac{1}{2}=0$```

Find the solutions of the equation using `solve`.

`sols = solve(eq,x)`
```sols =  $\left(\begin{array}{c}-\frac{\sqrt{2} \sqrt{2000000-{\pi }^{2}}-2000}{2 \pi }\\ \frac{\sqrt{2} \sqrt{2000000-{\pi }^{2}}+2000}{2 \pi }\end{array}\right)$```

Set the `'FloatingPointOutput'` preference to `true`. Display the quadratic equation and its solutions in floating-point format.

```sympref('FloatingPointOutput',true); eq```
`eq = ${x}^{2}-636.6198 x+0.5000=0$`
`sols`
```sols =  $\left(\begin{array}{c}7.8540e-04\\ 636.6190\end{array}\right)$```

The floating-point format displays each symbolic number in the short, fixed-decimal format with 4 digits after the decimal point. Setting the `'FloatingPointOutput'` preference does not affect the floating-point precision in a symbolic computation. To compute symbolic numbers using floating-point arithmetic, use the `vpa` function.

Now restore the default value of `'FloatingPointOutput'` by specifying the `'default'` option. Compute the floating-point approximation of the solutions in 8 significant digits using `vpa`.

```sympref('FloatingPointOutput','default'); sols = vpa(sols,8)```
```sols =  $\left(\begin{array}{c}0.00078539913\\ 636.61899\end{array}\right)$```

Create a symbolic polynomial expression consisting of multiple variables. Display the polynomial in the default order.

```syms x y a b p1 = b^2*x^2 + a^2*x + y^3 + 2```
`p1 = ${a}^{2} x+{b}^{2} {x}^{2}+{y}^{3}+2$`

The default option sorts the output in alphabetical order, without distinguishing the different symbolic variables in each monomial term.

Now display the same polynomial in ascending order by setting the preference `'PolynomialDisplayStyle'` to `'ascend'`.

```sympref('PolynomialDisplayStyle','ascend'); p1```
`p1 = $2+{y}^{3}+{a}^{2} x+{b}^{2} {x}^{2}$`

The `'ascend'` option sorts the output in ascending order based on the importance of the variables. Here, the most important variable `x` with the highest order in a monomial term is displayed last.

Display the polynomial in descending order by setting the `'PolynomialDisplayStyle'` preference to `'descend'`.

```sympref('PolynomialDisplayStyle','descend'); p1```
`p1 = ${b}^{2} {x}^{2}+{a}^{2} x+{y}^{3}+2$`

The preferences you set using `sympref` persist through your current and future MATLAB sessions. Restore the default value of `'PolynomialDisplayStyle'` by specifying the `'default'` option.

`sympref('PolynomialDisplayStyle','default');`

By default, a symbolic matrix in live scripts is set in parentheses (round brackets). You can specify the use of square brackets instead by using `sympref`.

Create a symbolic matrix consisting of symbolic variables and numbers.

```syms x y A = [x*y, 2; 4, y^2]```
```A =  $\left(\begin{array}{cc}x y& 2\\ 4& {y}^{2}\end{array}\right)$```

Display the matrix with square brackets by setting the `'MatrixWithSquareBrackets'` preference to `true`.

```sympref('MatrixWithSquareBrackets',true); A```
```A =  $\left[\begin{array}{cc}x y& 2\\ 4& {y}^{2}\end{array}\right]$```

The preferences you set using `sympref` persist through your current and future MATLAB sessions. Restore the default value by specifying the `'default'` option.

`sympref('MatrixWithSquareBrackets','default');`

Instead of saving and restoring individual preferences one by one, you can use `sympref` to save and restore all symbolic preferences simultaneously.

Return a structure containing the values of all symbolic preferences by using `sympref()`.

`oldPrefs = sympref()`
```oldPrefs = struct with fields: FourierParameters: [1 -1] HeavisideAtOrigin: 1/2 AbbreviateOutput: 1 TypesetOutput: 1 FloatingPointOutput: 0 PolynomialDisplayStyle: 'default' MatrixWithSquareBrackets: 0 ```

Access the value of each symbolic preference by addressing the field of the structure. Alternatively, you can use the command `sympref(pref)`.

`val1 = oldPrefs.FourierParameters`
`val1 = $\left(\begin{array}{cc}1& -1\end{array}\right)$`
`val2 = oldPrefs.HeavisideAtOrigin`
```val2 =  $\frac{1}{2}$```
`val3 = sympref('FourierParameters')`
`val3 = $\left(\begin{array}{cc}1& -1\end{array}\right)$`

To modify multiple symbolic preferences simultaneously, you can create a structure `prefs` that contains the preference values. Use the command `sympref(prefs)` to set multiple preferences.

`prefs.FourierParameters = [1/(2*sym(pi)) 1]`
```prefs = struct with fields: FourierParameters: [1/(2*pi) 1] ```
`prefs.HeavisideAtOrigin = 1`
```prefs = struct with fields: FourierParameters: [1/(2*pi) 1] HeavisideAtOrigin: 1 ```
`sympref(prefs);`

Because symbolic preferences persist through your current and future MATLAB sessions, you need to restore your previous preferences. Restore the saved preferences using `sympref(oldPrefs)`.

`sympref(oldPrefs);`

Alternatively, you can set all symbolic preferences to their default values by specifying the `'default'` option.

`sympref('default');`

## Input Arguments

collapse all

Symbolic preference, specified as a character vector or string. The value options for each symbolic preference follow.

PreferenceValueDescription
`'FourierParameters'`

Two-element row vector `[c,s]`. The parameters `c` and `s` must be numeric or symbolic numbers.

Default: `sym([1,-1])`.

Set the values of the parameters c and s in the Fourier transform:

`$F\left(w\right)=c\underset{-\infty }{\overset{\infty }{\int }}f\left(t\right){e}^{iswt}dt.$`

`'HeavisideAtOrigin'`

Scalar value, specified as a numeric or symbolic number.

Default: `sym(1/2)`.

Set the value of the Heaviside function `heaviside(0)` at the origin.

`'AbbreviateOutput'`

Logical value (boolean).

Default: logical `1` (`true`).

Specify whether or not to use abbreviated output format of symbolic variables and expressions in Live Scripts.

`'TypesetOutput'`

Logical value (boolean).

Default: logical `1` (`true`).

Typeset or use ASCII characters for the output of symbolic variables and expressions in Live Scripts.

`'FloatingPointOutput'`

Logical value (boolean).

Default: logical `0` (`false`).

Specify whether or not to display symbolic results in floating-point output format.

The `true` value option displays symbolic results in the short fixed-decimal format with 4 digits after the decimal point.

`'PolynomialDisplayStyle'`

Character vector or scalar string, specified as `'default'`, `'ascend'`, or `'descend'`.

Default: `'default'`.

Display a symbolic polynomial in default, ascending, or descending order.

• The `'default'` option sorts the output in alphabetical order, without distinguishing the different symbolic variables in each monomial term.

• The `'ascend'` option sorts the output in ascending order based on the standard mathematical notation for polynomials. For example, the variable `x` with the highest order in a monomial term is displayed last, preceded by monomial terms that contain the variables `y`, `z`, `t`, `s`, and so on.

• The `'descend'` option sorts the output in descending order based on the standard mathematical notation for polynomials. This option is the exact opposite of `'ascend'`.

`'MatrixWithSquareBrackets'`

Logical value (boolean).

Default: logical `0` (`false`).

Set matrices in round brackets or parentheses (round brackets) in Live Scripts.

Value of symbolic preference, specified as `'default'` or a valid value of the specified preference `pref`.

Symbolic preferences, specified as a structure array. You can set multiple preferences by declaring the field names and the valid preference values.

## Output Arguments

collapse all

Value of symbolic preference, returned as a valid value. `oldVal` represents the existing value of the preference `pref` before the call to `sympref`.

All symbolic preferences, returned as a structure array. `oldPrefs` represent the existing values of all preferences before the call to `sympref`.

## Tips

• The `clear` command does not reset or affect symbolic preferences. Use `sympref` to manipulate symbolic preferences.

• The symbolic preferences you set using `sympref` also determine the output generated by the `latex` and `mathml` functions.

• Setting the `'FloatingPointOutput'` preference affects only the output display format of symbolic numbers. To change the output display format of numeric numbers, use the `format` function. To compute symbolic numbers using floating-point precision, use the `vpa` or `digits` functions.