# symfunmatrix2symfun

Convert symbolic matrix function to symbolic function

Since R2022a

## Syntax

``f = symfunmatrix2symfun(fM)``

## Description

example

````f = symfunmatrix2symfun(fM)` converts a symbolic matrix function `fM` of type `symfunmatrix` to a symbolic function `f` of type `symfun`.The output symbolic function has the same matrix dimensions as the input symbolic matrix function, and its components are filled with automatically generated elements. For example, `syms fM(x) [1 2] matrix; f = symfunmatrix2symfun(fM)` converts the symbolic matrix function `fM(x)` to the symbolic function ```f(x) = [fM1_1(x), fM1_2(x)]```. The generated elements `fM1_1` and `fM1_2` do not appear in the MATLAB® workspace.```

## Examples

collapse all

Create `2`-by-`1` and `2`-by-`2` symbolic matrix variables to represent the matrices $\mathbit{X}$ and $\mathbit{A}$.

```syms X [2 1] matrix syms A [2 2] matrix```

Create two symbolic matrix functions to represent the functions $\mathit{F}\left(\mathbit{X},\mathbit{A}\right)$ and $\partial \mathit{F}\left(\mathbit{X},\mathbit{A}\right)/\partial {\mathbit{X}}^{\mathit{T}}$. When creating the symbolic matrix functions, keep existing definitions of the symbolic variables $\mathbit{X}$ and $\mathbit{A}$ in the workspace. The symbolic matrix functions require matrices of the same sizes as $\mathbit{X}$ and $\mathbit{A}$ as their input arguments.

```syms F(X,A) [1 1] matrix keepargs syms dF(X,A) [2 1] matrix keepargs```

Assign the function $\mathit{F}\left(\mathbit{X},\mathbit{A}\right)={\mathbit{X}}^{\mathit{T}}\text{\hspace{0.17em}}\mathbit{A}\text{\hspace{0.17em}}\mathbit{X}$ and find its derivative $\partial \mathit{F}\left(\mathbit{X},\mathbit{A}\right)/\partial {\mathbit{X}}^{\mathit{T}}$. The results are in matrix notation in terms of $\mathbit{X}$ and $\mathbit{A}$.

`F(X,A) = X.'*A*X`
`F(X, A) = ${X}^{\mathrm{T}} A X$`
`dF(X,A) = diff(F,X.')`
`dF(X, A) = $A X+{A}^{\mathrm{T}} X$`

Convert the symbolic matrix functions from data type `symfunmatrix` to `symfun`. The results are in scalar notation in terms of the matrix elements of $\mathbit{X}$ and $\mathbit{A}$. These functions accept scalars as their input arguments.

`Fsymfun = symfunmatrix2symfun(F)`
`Fsymfun(X1, X2, A1_1, A1_2, A2_1, A2_2) = ${X}_{1} \left({A}_{1,1} {X}_{1}+{A}_{1,2} {X}_{2}\right)+{X}_{2} \left({A}_{2,1} {X}_{1}+{A}_{2,2} {X}_{2}\right)$`
`dFsymfun = symfunmatrix2symfun(dF)`
```dFsymfun(X1, X2, A1_1, A1_2, A2_1, A2_2) =  $\left(\begin{array}{c}2 {A}_{1,1} {X}_{1}+{A}_{1,2} {X}_{2}+{A}_{2,1} {X}_{2}\\ {A}_{1,2} {X}_{1}+{A}_{2,1} {X}_{1}+2 {A}_{2,2} {X}_{2}\end{array}\right)$```

## Input Arguments

collapse all

Input, specified as a symbolic matrix function.

Data Types: `symfunmatrix`

## Tips

• To show all the functions in Symbolic Math Toolbox™ that accept symbolic matrix functions as input, use the command `methods symfunmatrix`.

## Version History

Introduced in R2022a