Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Create symbolic variables and functions

`syms `

creates
symbolic variables `var1 ... varN`

`var1 ... varN`

. Separate variables
by spaces.

`syms `

sets
an assumption that the created symbolic variables belong to a `var1 ... varN`

`set`

`set`

.

`syms `

clears
assumptions set on a symbolic variables `var1 ... varN`

clear`var1 ... varN`

.

`syms `

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

`f`

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

representing
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
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`

without input arguments lists all
symbolic variables, functions, vectors, and matrices currently existing
in the MATLAB^{®} workspace.

Create symbolic variables `x`

and `y`

.

syms x y

Create symbolic variables `x`

and `y`

,
and assume that they are integers.

syms x y integer

Check assumptions.

assumptions

ans = [ in(x, 'integer'), in(y, 'integer')]

Alternatively, check assumptions on each variable. For example,
check assumptions set on the variable `x`

.

assumptions(x)

ans = in(x, 'integer')

Clear assumptions on `x`

and `y`

.

assume([x y],'clear') assumptions

ans = Empty sym: 1-by-0

Create symbolic functions with one and two arguments.

syms s(t) f(x,y)

Both `s`

and `f`

are abstract
symbolic functions. They do not have symbolic expressions assigned
to them, so the bodies of these functions are `s(t)`

and `f(x,y)`

,
respectively.

Specify the following formula for `f`

.

f(x,y) = x + 2*y

f(x, y) = x + 2*y

Compute function value at the point `x = 1`

and ```
y
= 2
```

.

f(1,2)

ans = 5

Create a symbolic function and specify its formula by using a symbolic matrix.

syms x f(x) = [x x^3; x^2 x^4]

f(x) = [ x, x^3] [ x^2, x^4]

Compute the function value at the point `x = 2`

:

f(2)

ans = [ 2, 8] [ 4, 16]

Compute the value of this function for ```
x = [1 2 3;
4 5 6]
```

. The result is a cell array of symbolic matrices.

y = f([1 2 3; 4 5 6])

y = 2×2 cell array [2×3 sym] [2×3 sym] [2×3 sym] [2×3 sym]

Access the contents of a cell in the cell array by using braces.

y{1}

ans = [ 1, 2, 3] [ 4, 5, 6]

Certain functions, such as `solve`

and `symReadSSCVariables`

,
can return a vector of symbolic variables or a cell array of symbolic
variables and functions. These variables or functions do not automatically
appear in the MATLAB workspace. Create these variables or functions
from the vector or cell array by using `syms`

.

Solve the equation `sin(x) == 1`

by using `solve`

.
The parameter `k`

in the solution does not appear
in the MATLAB workspace.

syms x [sol, parameter, condition] = solve(sin(x) == 1, x, 'ReturnConditions', true); parameter

parameter = k

Create the parameter `k`

by using `syms`

.
The parameter `k`

now appears in the MATLAB workspace.

syms(parameter)

Similarly, use `syms`

to create the symbolic
objects contained in a vector or cell array. Examples of functions
that return a cell array of symbolic objects are `symReadSSCVariables`

and `symReadSSCParameters`

.

Create several symbolic variables, functions, and matrices.

syms a b c f(x,y) g(s,t) A = sym('A',[2,3]); B = sym('B',[1 10]);

Use `syms`

without input arguments to print
a list of all symbolic objects that currently exist in the MATLAB workspace.

syms

'A' 'B' 'a' 'b' 'c' 'f' 'g' 's' 't' 'x' 'y'

`assume`

| `assumeAlso`

| `assumptions`

| `clear all`

| `reset`

| `sym`

| `symfun`

| `symvar`

Was this topic helpful?