hasSymType

Determine whether symbolic object contains specific type

Syntax

TF = hasSymType(symObj,type)
TF = hasSymType(symObj,funType,vars)

Description

example

TF = hasSymType(symObj,type) returns logical 1 (true) if the symbolic object symObj contains a subobject 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.

example

TF = hasSymType(symObj,funType,vars) checks whether symObj contains an unassigned symbolic function that depends on the variables vars.

You can set the function type funType to 'symfunOf' or 'symfunDependingOn'. For example, syms f(x); hasSymType(f,'symfunOf',x) returns logical 1.

Examples

collapse all

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 = 

x+2π+12

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 = 

f(xn)+f(x)dx+2.7000=1i

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) = π+xy+f(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

collapse all

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 CategoryString ValuesExamples Returning Logical 1
numbers
  • 'integer' — integer numbers

  • 'rational' — rational numbers

  • 'vpareal' — variable-precision floating-point real numbers

  • 'complex' — complex numbers

  • 'real' — real numbers, including 'integer', 'rational', and 'vpareal'

  • 'number' — numbers, including 'integer', 'rational', 'vpareal', 'complex', and 'real'

  • hasSymType(sym(2),'integer')

  • hasSymType(sym(1/2),'rational')

  • hasSymType(vpa(0.5),'vpareal')

  • hasSymType(vpa(1i),'complex')

  • hasSymType([sym(1/2) vpa(0.5)],'real')

  • hasSymType([vpa(1i) sym(1/2)],'number')

constants'constant' — symbolic constants, including 'number'hasSymType([vpa(1i) sym(pi)],'constant')
symbolic math functions'vpa', 'sin', 'exp', and so on — symbolic math functions in symbolic expressionshasSymType(vpa(sym(pi)),'vpa')
unassigned symbolic functions
  • 'F', 'g', and so on — function name of an unassigned symbolic function

  • 'symfun' — unassigned symbolic functions

  • syms F(x); hasSymType(F(x+2),'F')

  • syms g(x); hasSymType(g(x),'symfun')

arithmetic operators
  • 'plus' — addition operator + and subtraction operator -

  • 'times' — multiplication operator * and division operator /

  • 'power' — power or exponentiation operator ^ and square root operator sqrt

  • syms x y; hasSymType(2*x + y,'plus')

  • syms x y; hasSymType(x*y,'times')

  • syms x y; hasSymType(x^(y+2),'power')

variables'variable' — symbolic variableshasSymType(sym('x'),'variable')
units'units' — symbolic unitshasSymType(symunit('m'),'units')
expressions'expression' — symbolic expressions, including all of the preceding symbolic types hasSymType(sym('x')+1,'expression')
logical expressions
  • 'or' — logical OR operator |

  • 'and' — logical AND operator &

  • 'not' — logical NOT operator ~

  • 'xor' — logical exclusive-OR operator xor

  • 'logicalexpression' — logical expressions, including 'or', 'and', 'not', and 'xor'

  • syms x y; hasSymType(x|y,'or')

  • syms x y; hasSymType(x&y,'and')

  • syms x; hasSymType(~x,'not')

  • syms x y; hasSymType(xor(x,y),'xor')

  • syms x y; hasSymType(~x|y,'logicalexpression')

equations and inequalities
  • 'eq' — equality operator ==

  • 'ne' — inequality operator ~=

  • 'lt' — less-than operator < or greater-than operator >

  • 'le' — less-than-or-equal-to operator <= or greater-than-or-equal-to operator >=

  • 'equation' — symbolic equations and inequalities, including 'eq', 'ne', 'lt', and 'le'

  • syms x; hasSymType(x==2,'eq')

  • syms x; hasSymType(x~=1,'ne')

  • syms x; hasSymType(x>0,'lt')

  • syms x; hasSymType(x<=2,'le')

  • syms x; hasSymType([x>0 x~=1],'equation')

unsupported symbolic types

'unsupported' — unsupported symbolic types

 

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.

Input variables, specified as symbolic variables or a symbolic array.

Tips

  • To check whether a symbolic expression contains a particular subexpression, use the has function.

Introduced in R2019a