findSymType

Find symbolic subobjects of specific type

Syntax

X = findSymType(symObj,type)
X = findSymType(symObj,funType,vars)

Description

example

X = findSymType(symObj,type) returns a vector of symbolic subobjects of type type from the symbolic object symObj. The input type must be a case-sensitive string scalar or character vector, and it can include a logical expression.

  • If symObj does not contain a symbolic subobject of type type, then findSymType returns an empty scalar.

  • If symObj contains several subexpressions of type type, then findSymType returns the largest matching subexpression.

example

X = findSymType(symObj,funType,vars) returns a vector of unassigned symbolic functions that depend on the variables vars from the symbolic input symObj.

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

Examples

collapse all

Find and return specific symbolic numbers and constants in a symbolic expression.

Create a symbolic expression.

expr = sym('1/2')*pi + vpa(pi)
expr = 4.7124

Find symbolic numbers of type 'integer'.

X = findSymType(expr,'integer')
X = (12)

Find symbolic numbers of type 'integer | real'.

X = findSymType(expr,'integer | real')
X = (0.50003.1416)

Find symbolic numbers of type 'vpareal'.

X = findSymType(expr,'vpareal')
X = 3.1416

Find symbolic numbers of type 'complex'.

X = findSymType(expr,'complex')
 
X =
 
Empty sym: 1-by-0
 

The findSymType function returns an empty scalar since the expression expr does not contain any complex numbers.

Now find symbolic constant of type 'constant'.

X = findSymType(expr,'constant')
X = 4.7124

When there are several subexpressions of type 'constant', findSymType returns the largest matching subexpression.

Find and return symbolic variables and functions in a symbolic equation.

Create a symbolic equation.

syms y(t) k
eq = diff(y) + k*y == sin(y)
eq(t) = 

t y(t)+ky(t)=sin(y(t))

Find symbolic variables of type 'variable' in the equation.

X = findSymType(eq,'variable')
X = (kt)

Find an unassigned symbolic function of type 'symfun' in the equation.

X = findSymType(eq,'symfun')
X = y(t)

Find a symbolic math function of type 'diff' in the equation.

X = findSymType(eq,'diff')
X = 

t y(t)

Find and return symbolic functions with specific variable dependencies in an expression.

Create a symbolic expression.

syms n f(x) g(x) y(x,t)
expr = x + f(x^n) + g(x)+ y(x,t)
expr = x+f(xn)+g(x)+y(x,t)

Find unassigned symbolic functions of type 'symfun' in the expression.

X = findSymType(expr,'symfun')
X = (f(xn)g(x)y(x,t))

Find symbolic functions that depend on the exact sequence of variables [x t] using 'symfunOf'.

X = findSymType(expr,'symfunOf',[x t])
X = y(x,t)

Find symbolic functions that have a dependency on the variable x using 'symfunDependingOn'.

X = findSymType(expr,'symfunDependingOn',x)
X = (g(x)y(x,t))

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 Values
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'

constants'constant' — symbolic constants, including 'number'
symbolic math functions'vpa', 'sin', 'exp', and so on — symbolic math functions in symbolic expressions
unassigned symbolic functions
  • 'F', 'g', and so on — function name of an unassigned symbolic function

  • 'symfun' — unassigned symbolic functions

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

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

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

variables'variable' — symbolic variables
units'units' — symbolic units
expressions'expression' — symbolic expressions, including all of the preceding symbolic types
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'

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'

unsupported symbolic types

'unsupported' — unsupported symbolic types

If symObj contains several subexpressions of type type, then findSymType returns the largest matching subexpression (topmost matching node in a tree data structure).

Function type, specified as 'symfunOf' or 'symfunDependingOn'.

  • 'symfunOf' finds and returns the unassigned symbolic functions that depend on the exact sequence of variables specified by the array vars. For example, syms f(x,y); findSymType(f,'symfunOf',[x y]) returns f(x,y).

  • 'symfunDependingOn' finds and returns the unassigned symbolic functions that have a dependency on the variables specified by the array vars. For example, syms f(x,y); findSymType(f,'symfunDependingOn',x) returns f(x,y).

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

Introduced in R2019a