General matrix function
F = funm(
A) for the
A. For details, see Matrix Function.
Matrix Cube Root
B, such that
A is a 3-by-3 identity matrix.
B3 = A,
compute the cube root of the matrix
A using the
Create the symbolic function
f(x) = x^(1/3) and
use it as the second argument for
funm. The cube
root of an identity matrix is the identity matrix itself.
A = sym(eye(3)) syms f(x) f(x) = x^(1/3); B = funm(A,f)
A = [ 1, 0, 0] [ 0, 1, 0] [ 0, 0, 1] B = [ 1, 0, 0] [ 0, 1, 0] [ 0, 0, 1]
Replace one of the
0 elements of matrix
compute the matrix cube root again.
A(1,2) = 1 B = funm(A,f)
A = [ 1, 1, 0] [ 0, 1, 0] [ 0, 0, 1] B = [ 1, 1/3, 0] [ 0, 1, 0] [ 0, 0, 1]
Now, compute the cube root of the upper triangular matrix.
A(1:2,2:3) = 1 B = funm(A,f)
A = [ 1, 1, 1] [ 0, 1, 1] [ 0, 0, 1] B = [ 1, 1/3, 2/9] [ 0, 1, 1/3] [ 0, 0, 1]
B3 = A.
ans = [ 1, 1, 1] [ 0, 1, 1] [ 0, 0, 1]
Matrix Lambert W Function
Find the matrix Lambert W function.
First, create a 3-by-3 matrix
A using variable-precision
arithmetic with five digit accuracy. In this example, using variable-precision
arithmetic instead of exact symbolic numbers lets you speed up computations
and decrease memory usage. Using only five digits helps the result
to fit on screen.
savedefault = digits(5); A = vpa(magic(3))
A = [ 8.0, 1.0, 6.0] [ 3.0, 5.0, 7.0] [ 4.0, 9.0, 2.0]
Create the symbolic function
f(x) = lambertw(x).
syms f(x) f(x) = lambertw(x);
To find the Lambert W function (
in a matrix sense, call
its second argument.
W0 = funm(A,f)
W0 = [ 1.5335 + 0.053465i, 0.11432 + 0.47579i, 0.36208 - 0.52925i] [ 0.21343 + 0.073771i, 1.3849 + 0.65649i, 0.41164 - 0.73026i] [ 0.26298 - 0.12724i, 0.51074 - 1.1323i, 1.2362 + 1.2595i]
Verify that this result is a solution of the matrix equation
= W0·eW0 within the specified
ans = [ 8.0, 1.0 - 5.6843e-13i, 6.0 + 1.1369e-13i] [ 3.0 - 2.2737e-13i, 5.0 - 2.8422e-14i, 7.0 - 4.1211e-13i] [ 4.0 - 2.2737e-13i, 9.0 - 9.9476e-14i, 2.0 + 1.4779e-12i]
Now, create the symbolic function
W-1 of the Lambert
f(x) = lambertw(-1,x);
for the matrix
Wm1 = funm(A,f)
Wm1 = [ 0.40925 - 4.7154i, 0.54204 + 0.5947i, 0.13764 - 0.80906i] [ 0.38028 + 0.033194i, 0.65189 - 3.8732i, 0.056763 - 1.0898i] [ 0.2994 - 0.24756i, - 0.105 - 1.6513i, 0.89453 - 3.0309i]
Verify that this result is the solution of the matrix equation
= Wm1·eWm1 within the specified
ans = [ 8.0 - 8.3844e-13i, 1.0 - 3.979e-13i, 6.0 - 9.0949e-13i] [ 3.0 - 9.6634e-13i, 5.0 + 1.684e-12i, 7.0 + 4.5475e-13i] [ 4.0 - 1.3642e-12i, 9.0 + 1.6698e-12i, 2.0 + 1.7053e-13i]
Matrix Exponential, Logarithm, and Square Root
You can use
appropriate second arguments to find matrix exponential, logarithm,
and square root. However, the more efficient approach is to use the
Create this square matrix and find its exponential, logarithm, and square root.
syms x A = [1 -1; 0 x] expA = expm(A) logA = logm(A) sqrtA = sqrtm(A)
A = [ 1, -1] [ 0, x] expA = [ exp(1), (exp(1) - exp(x))/(x - 1)] [ 0, exp(x)] logA = [ 0, -log(x)/(x - 1)] [ 0, log(x)] sqrtA = [ 1, 1/(x - 1) - x^(1/2)/(x - 1)] [ 0, x^(1/2)]
Find the matrix exponential, logarithm, and square root of
Use the symbolic expressions
sqrt(x) as the second argument of
The results are identical.
expA = funm(A,exp(x)) logA = funm(A,log(x)) sqrtA = funm(A,sqrt(x))
expA = [ exp(1), exp(1)/(x - 1) - exp(x)/(x - 1)] [ 0, exp(x)] logA = [ 0, -log(x)/(x - 1)] [ 0, log(x)] sqrtA = [ 1, 1/(x - 1) - x^(1/2)/(x - 1)] [ 0, x^(1/2)]
A — Input matrix
Input matrix, specified as a square symbolic or numeric matrix.
f — Function
symbolic function | symbolic expression
Function, specified as a symbolic function or expression.
F — Resulting matrix
Resulting function, returned as a symbolic matrix.
Matrix function is a scalar function that maps one matrix to another.
a scalar, has a Taylor series expansion. Then the matrix function
A is a matrix, is defined by the Taylor series
f(A), with addition and multiplication performed
in the matrix sense.
A can be represented as
A = P·D·P-1,
D is a diagonal matrix, such that
then the matrix function
f(A) can be computed
Non-diagonalizable matrices can be represented as
= P·J·P-1, where
a Jordan form of the matrix
A. Then, the matrix
f(A) can be computed by using the following
definition on each Jordan block:
For compatibility with the MATLAB®
funmaccepts the following arguments:
Function handles such as
@sin, as its second input argument.
optionsinput argument, such as
Additional input arguments of the function
f, such as
exitflagoutput argument, such as
[F,exitflag] = funm(A,f). Here,
1only if the
funmfunction call errors, for example, if it encounters a division by zero. Otherwise,
For more details and a list of all acceptable function handles, see the MATLAB
If the input matrix
Ais numeric (not a symbolic object) and the second argument
fis a function handle, then the
funmcall invokes the MATLAB
Introduced in R2014b