Shortcut for creating symbolic variables and functions

syms does not create variables with the following names: clearintegerpositiverational, and real. For example, in previous releases syms integer created the symbolic variable integer. To create these variables now, use sym. For example, to create the symbolic variable integer, use integer = sym('integer').




syms var1 ... varN creates symbolic variables var1 ... varN. Separate variables by spaces.


syms var1 ... varN set creates symbolic variables var1 ... varN simultaneously setting an assumption that these variables belong to a set.


syms var1 ... varN clear clears assumptions set on a symbolic variables var1 ... varN.


syms f(var1,...,varN) creates the symbolic function 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 without input arguments lists all symbolic variables, functions, vectors, and matrices currently existing in the MATLAB® workspace.


Create Symbolic Variables

Create symbolic variables x and y.

syms x y

Set Assumptions While Creating Variables

Create symbolic variables x and y, and assume that they are integer.

syms x y integer

Check assumptions.

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

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

ans =
in(x, 'integer')

Clear assumptions on x and y.

assume([x y],'clear')
ans =
Empty sym: 1-by-0

Create Symbolic Functions

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.

ans =

Create Symbolic Functions with Matrices as Formulas

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:

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 = 
    [2x3 sym]    [2x3 sym]
    [2x3 sym]    [2x3 sym]

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

ans =
[ 1, 2, 3]
[ 4, 5, 6]
ans =
[  1,  4,  9]
[ 16, 25, 36]
ans =
[  1,   8,  27]
[ 64, 125, 216]
ans =
[   1,  16,   81]
[ 256, 625, 1296]

List All Symbolic Variables, Functions, and Matrices

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.

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

Related Examples

Input Arguments

collapse all

var1 ... varN — Symbolic variablesvalid variable names separated by spaces

Symbolic variables, specified as valid variable names separated by spaces. Each variable name must begin with a letter and can contain only alphanumeric characters and underscores. To verify that the name is a valid variable name, use isvarname.

Example: x y123 z_1

set — Assumptions on symbolic variablesreal | positive | integer | rational

Assumptions on a symbolic variable or matrix, specified as real, positive, integer, or rational.

f(var1,...,varN) — Symbolic function with its input argumentsexpression with parentheses

Symbolic function with its input arguments, specified as an expression with parentheses. The function name f and the variable names var1...varN must be valid variable names. That is, they must begin with a letter and can contain only alphanumeric characters and underscores. To verify that the name is a valid variable name, use isvarname.

Example: s(t), f(x,y)

More About

collapse all


  • 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. You also can 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. 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:

    • assume(x,'clear') removes all assumptions affecting 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.

Introduced before R2006a

Was this topic helpful?