Main Content

symfunmatrix2symfun

Convert symbolic matrix function to symbolic function

Since R2022a

Description

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.

example

Examples

collapse all

Create 2-by-1 and 2-by-2 symbolic matrix variables to represent the matrices X and A.

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

Create two symbolic matrix functions to represent the functions F(X,A) and F(X,A)/XT. When creating the symbolic matrix functions, keep existing definitions of the symbolic matrix variables X and A in the workspace. The symbolic matrix functions require matrices of the same sizes as X and A as their input arguments.

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

Define the function F(X,A)=XTAX and find its derivative F(X,A)/XT. The resulting symbolic functions are in matrix notation in terms of X and A.

F(X,A) = X.'*A*X
F(X, A) = XTAX
dF(X,A) = diff(F,X.')
dF(X, A) = AX+ATX

Convert the symbolic matrix functions from data type symfunmatrix to symfun. The resulting symbolic functions are in scalar notation in terms of the matrix elements of X and A. These functions accept scalars as their input arguments.

Fsymfun = symfunmatrix2symfun(F)
Fsymfun(X1, X2, A1_1, A1_2, A2_1, A2_2) = X1A1,1X1+A1,2X2+X2A2,1X1+A2,2X2
dFsymfun = symfunmatrix2symfun(dF)
dFsymfun(X1, X2, A1_1, A1_2, A2_1, A2_2) = 

(2A1,1X1+A1,2X2+A2,1X2A1,2X1+A2,1X1+2A2,2X2)

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.

  • Instead of using symfunmatrix2symfun to convert a symbolic matrix function to a symbolic function, you can use the shortcut symfun. For an example, see Convert Symbolic Matrix Function to Symbolic Function. (since R2024b)

Version History

Introduced in R2022a

Go to top of page