# children

Subexpressions or terms of symbolic expression

## Description

example

children(expr) returns a vector containing the child subexpressions of the symbolic expression expr. For example, the child subexpressions of a sum are its terms.

example

children(A) returns a cell array containing the child subexpressions of each expression in A.

## Examples

### Find Child Subexpressions of Symbolic Expression

Find the child subexpressions of this expression. Child subexpressions of a sum are its terms.

syms x y
children(x^2 + x*y + y^2)
ans =
[ x*y, x^2, y^2]

Find the child subexpressions of this expression. This expression is also a sum, only some terms of that sum are negative.

children(x^2 - x*y - y^2)
ans =
[ -x*y, x^2, -y^2]

The child subexpression of a variable is the variable itself:

children(x)
ans =
x

### Find Child Subexpressions of Equation

Find the child subexpressions of this equation. The child subexpressions of an equation are the left and right sides of that equation.

syms x y
children(x^2 + x*y == y^2 + 1)
ans =
[ x^2 + y*x, y^2 + 1]

Find the child subexpressions of this inequality. The child subexpressions of an inequality are the left and right sides of that inequality.

children(sin(x) < cos(x))
ans =
[ sin(x), cos(x)]

### Find Child Subexpressions of Elements of Matrix

Call the children function for this matrix. The result is the cell array containing the child subexpressions of each element of the matrix.

syms x y
s = children([x + y, sin(x)*cos(y); x^3 - y^3, exp(x*y^2)])
s =
2×2 cell array
{1×2 sym}    {1×2 sym}
{1×2 sym}    {1×1 sym}

To access the contents of cells in the cell array, use braces:

s{1:4}
ans =
[ x, y]

ans =
[ x^3, -y^3]

ans =
[ cos(y), sin(x)]

ans =
x*y^2

## Input Arguments

collapse all

Input, specified as a symbolic number, variable, function, or expression.

Input, specified as a symbolic array.

#### Mathematical Modeling with Symbolic Math Toolbox

Get examples and videos