# syms

Create symbolic scalar variables and functions, and matrix variables and functions

## Syntax

## Description

### Symbolic Scalar Variables

`syms `

creates symbolic scalar
variables `var1 ... varN`

`var1 ... varN`

of type `sym`

. Separate the
different variables with spaces. This syntax clears all previous definitions of
`var1 ... varN`

.

`syms `

creates arrays of symbolic scalar variables `var1 ... varN`

`[n1 ... nM]`

`var1 ... varN`

, where each
array has the size
`n1`

-by-`...`

-by-`nM`

and contains
automatically generated symbolic scalar variables as its elements. For example,
`syms a [1 3]`

creates the symbolic array ```
a = [a1 a2
a3]
```

and the symbolic scalar variables `a1`

,
`a2`

, and `a3`

in the MATLAB^{®} workspace. For multidimensional arrays, these elements have the prefix
`a`

followed by the element’s index using `_`

as a
delimiter, such as `a1_3_2`

.

`syms `

creates `var1 ... varN`

`n`

`n`

-by-`n`

matrices of symbolic scalar variables
filled with automatically generated elements.

`syms ___ `

sets the assumption
that the created symbolic scalar variables belong to `set`

`set`

, and clears
other assumptions. Here, `set`

can be `real`

,
`positive`

, `integer`

, or `rational`

.
You can also combine multiple assumptions using spaces. For example, ```
syms x
positive rational
```

creates a symbolic scalar variable `x`

with
a positive rational value. Use this option in addition to any of the input argument
combinations in previous syntaxes.

### Symbolic Scalar Functions

`syms `

creates the symbolic
function `f(var1,...,varN)`

`f`

of type `symfun`

and the symbolic scalar
variables `var1,...,varN`

of type `sym`

, which represent
the input arguments of `f`

. This syntax clears all previous definitions
of `var1,...,varN`

including symbolic assumptions. The evaluated symbolic
function `f(var1,...,varN)`

is of type `sym`

.

`syms `

creates an `f(var1,...,varN)`

`[n1 ... nM]`

`n1`

-by-`...`

-by-`nM`

symbolic array with automatically generated symbolic functions as its elements. This
syntax also generates the symbolic scalar variables `var1,...,varN`

that
represent the input arguments of `f`

. For example, ```
syms f(x) [1
2]
```

creates the symbolic array `f(x) = [f1(x) f2(x)]`

, the
symbolic functions `f1`

and `f2`

, and the symbolic
scalar variable `x`

in the MATLAB workspace. For multidimensional arrays, these elements have the prefix
`f`

followed by the element’s index using `_`

as a
delimiter, such as `f1_3_2`

.

`syms `

creates an `f(var1,...,varN)`

`n`

`n`

-by-`n`

matrix of symbolic functions
filled with automatically generated elements.

### Symbolic Matrix Variables

`syms `

creates symbolic matrix variables `var1 ... varN`

`[nrow ncol]`

matrix`var1 ... varN`

of type
`symmatrix`

, where each symbolic matrix variable has the size
`nrow`

-by-`ncol`

. *(since
R2021a)*

`syms `

creates `var1 ... varN`

`n`

matrix`n`

-by-`n`

symbolic matrix variables.
*(since R2021a)*

### Symbolic Matrix Functions

`syms `

creates the symbolic matrix function `f(var1,...,varN)`

`[nrow ncol]`

matrix`f`

of type
`symfunmatrix`

and the symbolic scalar variables
`var1,...,varN`

of type `sym`

. The evaluated symbolic
matrix function `f(var1,...,varN)`

is of type
`symmatrix`

and has the size
`nrow`

-by-`ncol`

. This syntax clears all previous
definitions of `var1,...,varN`

including symbolic assumptions.
*(since R2022a)*

`syms `

keeps existing definitions of `f(var1,...,varN)`

`[nrow ncol]`

matrix keepargs`var1,...,varN`

in the workspace. If any of
the variables `var1,...,varN`

does not exist in the workspace, then this
syntax creates them as symbolic scalar variables of type `sym`

. The size
of the evaluated symbolic matrix function `f(var1,...,varN)`

is
`nrow`

-by-`ncol`

. *(since
R2022a)*

`syms `

creates a square symbolic matrix function, where the evaluated symbolic matrix function
`f(var1,...,varN)`

`n`

matrix`f(var1,...,varN)`

has the size
`n`

-by-`n`

. This syntax clears all previous
definitions of `var1,...,varN`

including symbolic assumptions.
*(since R2022a)*

`syms `

keeps existing definitions of `f(var1,...,varN)`

`n`

matrix keepargs`var1,...,varN`

in the workspace. If any of
the variables `var1,...,varN`

does not exist in the workspace, then this
syntax creates them as symbolic scalar variables of type `sym`

.
*(since R2022a)*

### Array of Symbolic Objects

`syms(`

creates the symbolic scalar variables
and functions contained in `symArray`

)`symArray`

, where
`symArray`

is either a vector of symbolic scalar variables or a cell
array of symbolic scalar variables and functions. This syntax clears all previous
definitions of variables specified in `symArray`

including symbolic
assumptions. Use this syntax only when such an array is returned by another function, such
as `solve`

or `symReadSSCVariables`

.

### Names of Symbolic Objects

`syms`

lists the names of all symbolic scalar variables, functions, matrix
variables, matrix functions, and arrays in the MATLAB workspace.

## Examples

## Input Arguments

## Output Arguments

## Limitations

Differentiation functions, such as

`divergence`

,`curl`

,`jacobian`

, and`laplacian`

, currently do not accept symbolic matrix variables and symbolic matrix functions as input. To evaluate differentiation with respect to vectors and matrices, use the`diff`

function instead.To show all the functions in Symbolic Math Toolbox™ that accept symbolic matrix variables and symbolic matrix functions as input, use the command

`methods symmatrix`

and`methods symfunmatrix`

.

## Tips

You can create multiple symbolic objects in one call. For example,

`syms f(x) g(t) y`

creates two symbolic functions (`f`

and`g`

) and three symbolic scalar variables (`x`

,`t`

, and`y`

).`syms`

is a shortcut for`sym`

,`symfun`

,`symmatrix`

, and`symfunmatrix`

. This shortcut lets you create several symbolic objects with one function call. For example, you can use`sym`

and create each symbolic scalar variable separately. However, when you create variables using`sym`

, any existing assumptions on the created variables are retained. You can also use`symfun`

to create symbolic functions.In functions and scripts, do not use

`syms`

to create symbolic scalar variables with the same names as MATLAB functions. For these names, MATLAB does not create symbolic scalar variables, but keeps the names assigned to the MATLAB functions. If you want to create a symbolic scalar variable with the same name as a MATLAB function inside a function or a script, use`sym`

instead. For example, use`alpha = sym('alpha')`

.Avoid using

`syms`

within functions or parallel for loops because it generates variables without direct output assignment and modifies the global state of the workspace. Using`syms`

within functions can create side effects and other unexpected behaviors. Instead, use`sym`

with left-side output assignment, such as`t = sym('t')`

. For more details, see Choose syms or sym Function.These variable names are invalid with

`syms`

:`integer`

,`real`

,`rational`

,`positive`

, and`clear`

. To create symbolic scalar variables with these names, use`sym`

. For example,`real = sym('real')`

.`clear x`

does not clear the symbolic object of its assumptions, such as real, positive, or any assumptions set by`assume`

,`sym`

, or`syms`

. To remove assumptions, use one of these options:`syms x`

or`syms f(x)`

clears all assumptions from`x`

.`assume(x,'clear')`

clears all assumptions from`x`

.`clear all`

clears all objects in the MATLAB workspace and resets the symbolic engine.`assume`

and`assumeAlso`

provide more flexibility for setting assumptions on symbolic scalar variables.

When you replace one or more elements of a numeric vector or matrix with a symbolic number, MATLAB converts that number to a double-precision number.

A = eye(3); A(1,1) = sym(pi)

A = 3.1416 0 0 0 1.0000 0 0 0 1.0000

You cannot replace elements of a numeric vector or matrix with a symbolic scalar variable, expression, or function because these elements cannot be converted to double-precision numbers. For example,

`syms a; A(1,1) = a`

throws an error.When evaluating a symbolic matrix function, you must substitute values that have the same size as the defined input arguments. For example, see Create Function of Vector and Scalar. For comparison, this example returns an error:

syms X [2 2] matrix syms f(X) [1 1] matrix keepargs f(ones(4))

## Version History

**Introduced before R2006a**

## See Also

`assume`

| `assumeAlso`

| `assumptions`

| `displayFormula`

| `isvarname`

| `sym`

| `symfun`

| `symmatrix`

| `symfunmatrix`

| `symvar`

### Topics

- Create Symbolic Numbers, Variables, and Expressions
- Create Symbolic Functions
- Create Symbolic Matrices
- Create Symbolic Matrix Variables
- Use Symbolic Objects to Represent Mathematical Objects
- Choose syms or sym Function
- Use Assumptions on Symbolic Variables
- Add Subscripts, Superscripts, and Accents to Symbolic Variables in the Live Editor
- Change Output Format of Symbolic and Variable-Precision Arithmetic