Main Content

symType

Determine type of symbolic object

Since R2019a

Description

example

s = symType(symObj) returns the type of a symbolic object. For example, symType(sym('x')) returns "variable".

Examples

collapse all

Create a symbolic number and determine its type.

a = sym('3/9');
s = symType(a)
s = 
"rational"

Now construct a symbolic array by including symbolic numbers in the array elements. Determine the symbolic type of each array element.

B = [-5, a, vpa(a), 1i, pi];
s = symType(B)
s = 1x5 string
    "integer"    "rational"    "vpareal"    "complex"    "constant"

Create a symbolic function f(x) using syms.

syms f(x)

Determine the type of the function. Because f(x) is an unassigned symbolic function, it has the symbolic type "symfun".

s = symType(f)
s = 
"symfun"

Assigning a mathematical expression to f(x) changes its symbolic type.

f(x) = x^2;
s = symType(f)
s = 
"expression"

Now check the symbolic type of f(x) = x and its derivative.

f(x) = x;
s = symType(f)
s = 
"variable"
s = symType(diff(f))
s = 
"integer"

Determine the type of various symbolic objects when solving for inequalities.

Create a quadratic function.

syms y(x)
y(x) = 100 - 5*x^2
y(x) = 100-5x2

Set two inequalities to the quadratic function. Check the symbolic type of each inequality.

eq1 = y(x) > 10;
eq2 = x > 2;
s = symType([eq1 eq2])
s = 1x2 string
    "equation"    "equation"

Solve the inequalities using solve. Return the solutions by setting 'ReturnConditions' to true.

eqSol = solve([eq1 eq2], 'ReturnConditions', true);
sols = eqSol.conditions
sols = x<182<x

Determine the symbolic type of the solutions.

s = symType(sols)
s = 
"logicalexpression"

Input Arguments

collapse all

Symbolic objects, specified as symbolic numbers, symbolic variables, symbolic expressions, symbolic functions, or symbolic units.

Output Arguments

collapse all

Symbolic types, returned as a string array. This table shows output values for various symbolic objects.

OutputDescriptionInput Example
"integer"symbolic integer numbersymType(sym('-1'))
"rational"symbolic rational numbersymType(sym('1/2'))
"vpareal"symbolic variable-precision floating-point real numbersymType([sym('1.5') vpa('3/2')])
"complex"symbolic complex numbersymType(sym('1+2i'))
"constant"symbolic mathematical constantsymType(sym([pi catalan]))
"variable"symbolic variablesyms x; symType(x)
"symfun"unassigned symbolic functionsyms f(x); symType(f)
"expression"symbolic expressionsyms x; symType(sqrt(x))
"equation"symbolic equation and inequalitysyms x; symType(x>=0)
"unit"symbolic unitsymType(symunit('meter'))
"logicalexpression"symbolic logical expressionsyms x y; symType(x|y)
"logicalconstant"symbolic logical constantsymType([symtrue symfalse])
"unsupported"symbolic object not supported by symType 

Version History

Introduced in R2019a