isSymType
Determine whether symbolic object is specific type
Description
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
.
Examples
Symbolic Number and Constant
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
Topmost Operator of Symbolic Expression
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
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 =
Symbolic Function of Multiple Variables
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
Input Arguments
symObj
— Symbolic objects
symbolic expressions | symbolic functions | symbolic variables | symbolic numbers | symbolic units
Symbolic objects, specified as symbolic expressions, symbolic functions, symbolic variables, symbolic numbers, or symbolic units.
type
— Symbolic types
scalar string | character vector
Symbolic 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 | 'unit' — symbolic units | isSymType(symunit('m'),'unit') |
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 whethersymObj
is an unassigned symbolic function that depends on the exact sequence of variables specified by the arrayvars
. For example,syms f(x,y); isSymType(f,'symfunOf',[x y])
returns logical1
.'symfunDependingOn'
checks whethersymObj
is an unassigned symbolic function that depends on the variables specified by the arrayvars
. For example,syms f(x,y); isSymType(f,'symfunDependingOn',x)
returns logical1
.
vars
— Input variables
symbolic variables | symbolic array
Input variables, specified as symbolic variables or a symbolic array.
Version History
Introduced in R2019a
See Also
symFunType
| hasSymType
| symType
| sym
| syms
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)