Skip to Main Content Skip to Search
Product Documentation

syms - Shortcut for creating symbolic variables and functions

Syntax

syms var1 ... varN
syms var1 ... varN set
syms var1 ... varN clear
syms f(arg1,...,argN)

Description

syms var1 ... varN creates symbolic variables var1 ... varN.

syms var1 ... varN set creates symbolic variables var1 ... varN and states that these variables belong to set.

syms var1 ... varN clear removes assumptions previously set on symbolic variables var1 ... varN.

syms f(arg1,...,argN) creates the symbolic function f and symbolic variables arg1,...,argN representing the input arguments of f.

Tips

Input Arguments

var1 ... varN

Names of symbolic variables. Each name must begin with a letter and contain only alphanumeric characters.

set

Either real or positive.

f

Name of a symbolic function. It must begin with a letter and contain only alphanumeric characters.

arg1,...,argN

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.

Examples

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:

assumptions(x)
assumptions(y)
ans =
x in R_
 
ans =
y in R_

Clear the assumptions that x and y are real:

syms x y clear
assumptions
ans =
[ empty sym ]
 

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:

f(1, 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:

f(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:

y{1}
ans =
[ 1, 2]
[ 3, 4]
y{2}
ans =
[  1,  8]
[ 27, 64]
y{3}
ans =
[ 1,  4]
[ 9, 16]
y{4}
ans =
[  1,  16]
[ 81, 256]

Alternatives

See Also

assume | assumeAlso | assumptions | clear all | reset | sym | symfun | symvar

More About

  


Free Symbolic Math Interactive Kit

See how symbolic computations can help you find analytical solutions to math and engineering problems.

Get free kit

Trials Available

Try the latest version of symbolic math products.

Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS