hasSymType
Determine whether symbolic object contains specific type
Description
Examples
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 + pig(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
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' | 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 | 'unit' — symbolic units | hasSymType(symunit('m'),'unit') |
| expressions | 'expression' — symbolic expressions, including all of
the preceding symbolic types | hasSymType(sym('x')+1,'expression') |
| logical expressions |
|
|
| equations and inequalities |
|
|
| unsupported symbolic types |
|
Function type, specified as 'symfunOf' or
'symfunDependingOn'.
'symfunOf'checks whethersymObjcontains an unassigned symbolic function that depends on the exact sequence of variables specified by the arrayvars. For example,syms f(x,y); hasSymType(f,'symfunOf',[x y])returns logical1.'symfunDependingOn'checks whethersymObjcontains an unassigned symbolic function that has a dependency on the variables specified by the arrayvars. For example,syms f(x,y); hasSymType(f,'symfunDependingOn',[y x])returns logical1.
Input variables, specified as symbolic variables or a symbolic array.
Tips
To check whether a symbolic expression contains a particular subexpression, use the
hasfunction.
Version History
Introduced in R2019a
See Also
has | symFunType | isSymType | symType | sym | syms | mapSymType | findSymType
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.
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
So erhalten Sie die bestmögliche Leistung auf der Website
Wählen Sie für die bestmögliche Website-Leistung die Website für China (auf Chinesisch oder Englisch). Andere landesspezifische Websites von MathWorks sind für Besuche von Ihrem Standort aus nicht optimiert.
Amerika
- 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)