Main Content

Create symbolic variables and functions

`syms `

creates symbolic
variables `var1 ... varN`

`var1 ... varN`

. Separate different variables by spaces.
`syms`

clears all assumptions from the variables.

`syms `

creates symbolic arrays `var1 ... varN`

`[n1 ... nM]`

`var1 ... varN`

, where each array has the size
`n1`

-by-`...`

-by-`nM`

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

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

and the
symbolic 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`

symbolic matrices filled with automatically
generated elements.

`syms ___ `

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

`set`

, and clears other
assumptions. Here, `set`

can be `real`

,
`positive`

, `integer`

, or `rational`

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

creates a variable `x`

with a positive
rational value.

`syms `

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

`f`

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

,
which represent the input arguments of `f`

. You can create multiple
symbolic functions in one call. For example, `syms f(x) g(t)`

creates two
symbolic functions (`f`

and `g`

) and two symbolic
variables (`x`

and `t`

).

`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 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(x)`

and `f2(x)`

, and the symbolic
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`

symbolic matrix filled with automatically
generated elements.

`syms(`

creates
the symbolic variables and functions contained in `symArray`

)`symArray`

,
where `symArray`

is either a vector of symbolic
variables or a cell array of symbolic variables and functions. Use
this syntax only when such an array is returned by another function,
such as `solve`

or `symReadSSCVariables`

.

`syms`

is a shortcut for`sym`

. This shortcut lets you create several symbolic variables in one function call. Alternatively, you can use`sym`

and create each 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 variables with the same names as MATLAB functions. For these names, MATLAB does not create symbolic variables, but keeps the names assigned to the functions. If you want to create a symbolic variable with the same name as a MATLAB function inside a function or a script, use`sym`

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

.The following variable names are invalid with

`syms`

:`integer`

,`real`

,`rational`

,`positive`

, and`clear`

. To create 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`

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 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 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.

`assume`

| `assumeAlso`

| `assumptions`

| `isvarname`

| `reset`

| `sym`

| `symfun`

| `symvar`