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
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 = 1×5 logical array
1 1 0 1 0
Check whether each array element is of type 'integer | real'.
TF = isSymType(N,'integer | real')TF = 1×5 logical array
1 1 0 1 0
Check whether each array element is of type 'number'.
TF = isSymType(N,'number')TF = 1×5 logical array
1 1 0 1 1
Check whether each array element is of type 'constant'.
TF = isSymType(N,'constant')TF = 1×5 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 - 1expr =
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 = 1×3 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
Input Arguments
Symbolic objects, specified as symbolic expressions, symbolic functions, symbolic variables, symbolic numbers, or symbolic units.
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 |
|
Function type, specified as 'symfunOf' or
'symfunDependingOn'.
'symfunOf'checks whethersymObjis 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 whethersymObjis 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.
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.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- 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)