Determine whether symbolic object contains specific type
Determine whether a symbolic expression contains a symbolic variable, constant, or number of a specific type.
Create a symbolic expression.
syms x; expr = sym('1/2') + 2*pi + x
expr =
Check whether expr
contains a symbolic variable of type 'variable'
.
TF = hasSymType(expr,'variable')
TF = logical
1
Check whether expr
contains a symbolic constant of type 'constant'
.
TF = hasSymType(expr,'constant')
TF = logical
1
Check whether expr
contains a symbolic number of type 'integer'
.
TF = hasSymType(expr,'integer')
TF = logical
1
Check whether expr
contains a symbolic number of type 'integer | real'
.
TF = hasSymType(expr,'integer | real')
TF = logical
1
Check whether expr
contains a symbolic number of type 'complex'
.
TF = hasSymType(expr,'complex')
TF = logical
0
Determine whether a symbolic equation contains a symbolic function or operator of a specific type.
Create a symbolic equation.
syms f(x) n eq = f(x^n) + int(f(x),x) + vpa(2.7) == 1i
eq =
Check whether eq
contains the symbolic function 'f'
.
TF = hasSymType(eq,'f')
TF = logical
1
Check whether eq
contains an unassigned symbolic function of type 'symfun'
.
TF = hasSymType(eq,'symfun')
TF = logical
1
Check whether eq
contains a symbolic math function of type 'int'
.
TF = hasSymType(eq,'int')
TF = logical
1
Check whether eq
contains an operator of type 'power'
.
TF = hasSymType(eq,'power')
TF = logical
1
Create a symbolic function of multiple variables using syms
.
syms f(x,y,z)
g = f + x*y + pi
g(x, y, z) =
Check whether g
depends on the exact variable x
using 'symfunOf'
.
TF = hasSymType(g,'symfunOf',x)
TF = logical
0
Check whether g
depends on the exact sequence of variables [x y z]
using 'symfunOf'
.
TF = hasSymType(g,'symfunOf',[x y z])
TF = logical
1
Check whether g
has any dependency on the variables [y x]
using 'symfunDependingOn'
.
TF = hasSymType(g,'symfunDependingOn',[y x])
TF = logical
1
symObj
— Symbolic objectsSymbolic objects, specified as symbolic expressions, symbolic functions, symbolic variables, symbolic numbers, or symbolic units.
type
— Symbolic typesSymbolic types, specified as a case-sensitive scalar string or character vector. The
input type
can contain a logical expression. The value options
follow.
Symbolic Type Category | String Values | Examples Returning Logical 1 |
---|---|---|
numbers |
|
|
constants | 'constant' — symbolic mathematical constants,
including 'number' | hasSymType([sym(pi) vpa(1i)],'constant') |
symbolic math functions | 'vpa' , 'sin' ,
'exp' , and so on — symbolic math functions in symbolic
expressions | hasSymType(vpa(sym(pi)),'vpa') |
unassigned symbolic functions |
|
|
arithmetic operators |
|
|
variables | 'variable' — symbolic variables | hasSymType(sym('x'),'variable') |
units | 'units' — symbolic units | hasSymType(symunit('m'),'units') |
expressions | 'expression' — symbolic expressions, including all of
the preceding symbolic types | hasSymType(sym('x')+1,'expression') |
logical expressions |
|
|
equations and inequalities |
|
|
unsupported symbolic types |
|
funType
— Function type'symfunOf'
| 'symfunDependingOn'
Function type, specified as 'symfunOf'
or
'symfunDependingOn'
.
'symfunOf'
checks whether symObj
contains an unassigned symbolic function that depends on the exact sequence of
variables specified by the array vars
. For example,
syms f(x,y); hasSymType(f,'symfunOf',[x y])
returns logical
1
.
'symfunDependingOn'
checks whether
symObj
contains an unassigned symbolic function that has a
dependency on the variables specified by the array vars
. For
example, syms f(x,y); hasSymType(f,'symfunDependingOn',[y x])
returns logical 1
.
vars
— Input variablesInput variables, specified as symbolic variables or a symbolic array.
To check whether a symbolic expression contains a particular subexpression, use the
has
function.
findSymType
| has
| isSymType
| mapSymType
| sym
| symFunType
| syms
| symType
You have a modified version of this example. Do you want to open this example with your edits?