Shortcut for creating symbolic variables and functions
syms var1 ... varN
syms var1 ... varN set
syms var1 ... varN clear
syms var1 ... varN creates symbolic variables var1 ... varN.
syms var1 ... varN clear removes assumptions previously set on symbolic variables var1 ... varN.
var1 ... varN
Names of symbolic variables. Each name must begin with a letter and contain only alphanumeric characters.
Either real or positive.
Name of a symbolic function. It must begin with a letter and contain only alphanumeric characters.
Arguments of a symbolic function. For each argument, syms creates a symbolic variable. Argument names must begin with a letter and contain only alphanumeric characters.
Create symbolic variables x and y using syms:
syms x y
Create symbolic variables x and y, and assume that they are real:
syms x y real
To see assumptions set on x and y, use assumptions:
ans = in(x, 'real') ans = in(y, 'real')
Clear the assumptions that x and y are real:
syms x y clear assumptions
ans = Empty sym: 1-by-0
Create a symbolic function f that accepts two arguments, x and y:
syms f(x, y)
Specify the formula for this function:
f(x, y) = x + 2*y
f(x, y) = x + 2*y
Compute the function value at the point x = 1 and y = 2:
ans = 5
Create symbolic function f and specify its formula by this symbolic matrix:
syms x f(x) = [x x^2; x^3 x^4];
Compute the function value at the point x = 2:
ans = [ 2, 4] [ 8, 16]
Now compute the value of this function for x = [1 2; 3 4]. The result is a cell array of symbolic matrices:
y = f([1 2; 3 4])
y = [2x2 sym] [2x2 sym] [2x2 sym] [2x2 sym]
To access the contents of each cell in a cell array, use braces:
ans = [ 1, 2] [ 3, 4]
ans = [ 1, 8] [ 27, 64]
ans = [ 1, 4] [ 9, 16]
ans = [ 1, 16] [ 81, 256]
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:
var1 = sym('var1'); ... varN = sym('varN');
sym also lets you create real variables or positive variables. It also lets you clear assumptions set on a variable.
assume and assumeAlso provide more flexibility for setting assumptions on variable.
When creating a symbolic function, use syms to create arg1,...,argN as symbolic variables. Then use the assignment operation to create the symbolic function f, for example:
syms x y f(x, y) = x + y
For compatibility with previous versions, syms var1 ... varN unreal is equivalent to syms var1 ... varN clear.
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 some MATLAB function inside a function or a script, use sym. For example:
alpha = sym('alpha')
clear x does not clear the symbolic object of its assumptions, such as real, positive, or any assumptions set by assume. To remove assumptions, use one of these options:
syms x clear removes assumptions from x without affecting any other symbolic variables.
reset(symengine) resets the symbolic engine and therefore removes assumptions on all variables. The variables themselves remain in the MATLAB workspace.
clear all removes all objects in the MATLAB workspace and resets the symbolic engine.