findSymType

Find symbolic subobjects of specific type

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 =

$\frac{\pi }{2}+3.1415926535897932384626433832795$

Find symbolic numbers of type 'integer'.

X = findSymType(expr,'integer')
X = $\left(\begin{array}{cc}1& 2\end{array}\right)$

Find symbolic numbers of type 'integer | real'.

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

$\left(\begin{array}{cc}\frac{1}{2}& 3.1415926535897932384626433832795\end{array}\right)$

Find symbolic numbers of type 'vpareal'.

X = findSymType(expr,'vpareal')
X = $3.1415926535897932384626433832795$

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 =

$\frac{\pi }{2}+3.1415926535897932384626433832795$

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) =

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

X = findSymType(eq,'variable')
X = $\left(\begin{array}{cc}k& t\end{array}\right)$

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

X = findSymType(eq,'symfun')
X = $y\left(t\right)$

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

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

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\left({x}^{n}\right)+g\left(x\right)+y\left(x,t\right)$

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

X = findSymType(expr,'symfun')
X = $\left(\begin{array}{ccc}f\left({x}^{n}\right)& g\left(x\right)& y\left(x,t\right)\end{array}\right)$

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

X = findSymType(expr,'symfunOf',[x t])
X = $y\left(x,t\right)$

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

X = findSymType(expr,'symfunDependingOn',x)
X = $\left(\begin{array}{cc}g\left(x\right)& y\left(x,t\right)\end{array}\right)$

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 mathematical 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'unit' — 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

• 'logicalconstant' — symbolic logical constants symtrue and symfalse

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

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.