isSymType

Determine whether symbolic object is specific type

Syntax

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

Description

example

TF = isSymType(symObj,type) returns logical 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.

example

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

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

Examples

collapse all

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 = 

(120.5π3.1415926535897932384626433832795i)

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 = x2+2x-1

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 = x2+2x-1

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 = (x(t)=cos(t)r(t)y(t)=r(t)sin(t)r(t)=5)

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 = r(t)=5

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

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'

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

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

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

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

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

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

constants'constant' — symbolic constants, including 'number'isSymType([vpa(1i) sym(pi)],'constant')
symbolic math functions'vpa', 'sin', 'exp', and so on — topmost symbolic math functions in symbolic expressionsisSymType(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); isSymType(F(x+2),'F')

  • syms g(x); isSymType(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; isSymType(2*x + y,'plus')

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

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

variables'variable' — symbolic variablesisSymType(sym('x'),'variable')
units'units' — symbolic unitsisSymType(symunit('m'),'units')
expressions'expression' — symbolic expressions, including all of the preceding symbolic types isSymType(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; isSymType(x|y,'or')

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

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

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

  • syms x y; isSymType(~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; isSymType(x==2,'eq')

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

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

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

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

unsupported symbolic types

'unsupported' — unsupported symbolic types

 

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.

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

Introduced in R2019a