Determine whether symbolic object is specific type
returns logical TF
= isSymType(symObj
,type
)1
(true
) if the symbolic object
symObj
is of type type
, and logical
0
(false
) otherwise. The input
type
must be a case-sensitive string scalar or character vector, and it
can include a logical expression. For example, isSymType(sym('3'),'real &
integer')
returns logical 1
.
If symObj
is a symbolic expression with a topmost operator of type
type
, then isSymType(symObj,type)
also returns
logical 1
.
Create a symbolic number. Check whether the symbolic number is of type 'rational'
.
a = sym('1/2'); TF = isSymType(a,'rational')
TF = logical
1
Now construct a symbolic array by including symbolic numbers or constants in the array elements.
N = [sym('1/2'), vpa(0.5), pi, vpa(pi), 1i]
N =
Check whether each array element is of type 'real'
.
TF = isSymType(N,'real')
TF = 1x5 logical array
1 1 0 1 0
Check whether each array element is of type 'integer | real'
.
TF = isSymType(N,'integer | real')
TF = 1x5 logical array
1 1 0 1 0
Check whether each array element is of type 'number'
.
TF = isSymType(N,'number')
TF = 1x5 logical array
1 1 0 1 1
Check whether each array element is of type 'constant'
.
TF = isSymType(N,'constant')
TF = 1x5 logical array
1 1 1 1 1
Determine whether the topmost operator of a symbolic expression is of a specific type, such as 'plus'
or 'power'
.
Create a symbolic expression.
syms x
expr = x^2 + 2*x - 1
expr =
Check whether the topmost operator of expr
is of type 'plus'
.
TF = isSymType(expr,'plus')
TF = logical
1
Check whether the topmost operator of expr
is of type 'power'
.
TF = isSymType(expr,'power')
TF = logical
0
Now perform a symbolic square root operation in the expression.
expr = sqrt(x^2 + 2*x - 1)
expr =
Check whether the topmost operator of expr
is of type 'power'
.
TF = isSymType(expr,'power')
TF = logical
1
Select specific equations that are constant on the right side.
Create an array of three symbolic equations.
syms r(t) x(t) y(t) eq1 = [x(t) == r(t)*cos(t), y(t) == r(t)*sin(t), r(t) == 5]
eq1 =
Select the right side of each equation using the rhs
function. Check whether the right side of each equation is of type 'constant'
.
TF = isSymType(rhs(eq1),'constant')
TF = 1x3 logical array
0 0 1
Return the reduced equation that is constant on the right side.
eq2 = eq1(TF)
eq2 =
Create a symbolic function of multiple variables f(x,y)
using syms
. Check whether the unassigned symbolic function f
is of type 'symfun'
.
syms f(x,y) TF = isSymType(f,'symfun')
TF = logical
1
Check whether f
depends on the exact variable x
.
TF = isSymType(f,'symfunOf',x)
TF = logical
0
Check whether f
depends on the exact sequence of variables [x y]
.
TF = isSymType(f,'symfunOf',[x y])
TF = logical
1
Check whether f
depends on the variable x
.
TF = isSymType(f,'symfunDependingOn',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' | isSymType([sym(pi) vpa(1i)],'constant') |
symbolic math functions | 'vpa' , 'sin' ,
'exp' , and so on — topmost symbolic math functions in
symbolic expressions | isSymType(vpa(sym(pi)),'vpa') |
unassigned symbolic functions |
|
|
arithmetic operators |
|
|
variables | 'variable' — symbolic variables | isSymType(sym('x'),'variable') |
units | 'units' — symbolic units | isSymType(symunit('m'),'units') |
expressions | 'expression' — symbolic expressions, including all of
the preceding symbolic types | isSymType(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
is an
unassigned symbolic function that depends on the exact sequence of variables
specified by the array vars
. For example, syms f(x,y);
isSymType(f,'symfunOf',[x y])
returns logical
1
.
'symfunDependingOn'
checks whether
symObj
is an unassigned symbolic function that depends on the
variables specified by the array vars
. For example,
syms f(x,y); isSymType(f,'symfunDependingOn',x)
returns
logical 1
.
vars
— Input variablesInput variables, specified as symbolic variables or a symbolic array.
hasSymType
| sym
| symFunType
| syms
| symType
You have a modified version of this example. Do you want to open this example with your edits?