syms

Creates symbolic variables and functions in the workspace.

Category: Symbolic Computations in MATLAB > Symbolic Variables, Expressions, Functions, and Preferences

Syntax

syms x y z

Creates the symbolic variables x, y and z.

syms x y real

Creates variables with an assumption such as real, positive or integer.

syms f(x, y)

Creates a symbolic function with arguments x and y.

syms

With no arguments, lists the symbolic variables in the workspace.

Description

syms x is a command-syntax shorthand for x = sym('x'): it puts a symbolic variable named x in the workspace so that expressions such as x^2 + 1 stay symbolic instead of being evaluated. Without an assumption, a variable is treated as an arbitrary complex number.

Assumptions let functions simplify more: for a variable declared real, conj(x) is just x. They are stored with the variable and queried with assumptions.

Input arguments

x y z
Names of the variables to create, separated by spaces.
assumption
Optional trailing word: real, positive, integer, rational, or clear to drop assumptions.

Example

Variables and a symbolic function

syms a b
expand((a + b)^2)
syms g(t)
g(t) = t^2;
g(3)
Output
ans = a^2 + 2*a*b + b^2
ans = 9

Notes

In MatLivre only the real assumption is recorded; positive and integer are accepted, but assumptions reports real and simplify does not use the extra information.

See also

sym symfun assumptions assume clear