Why does expm command work too slow?

12 次查看(过去 30 天)
Volcano
Volcano 2023-11-10
评论: Star Strider 2023-11-10
Hi, I am trying to calculate exponential of a matrix using expm command, however computation speed is too slow, compared to exp. Is there any way to obtain faster response from expm? Thanks...
A_aug = rand(6,6);
B_aug = rand(6,1);
syms t
M2 = expm(A_aug * t) * B_aug
  2 个评论
Volcano
Volcano 2023-11-10
编辑:Volcano 2023-11-10
It is interesting that, the code below works faster.
A_aug = eye(6,6);
B_aug = rand(6,1);
syms t
M2 = expm(A_aug * t) * B_aug
Matt J
Matt J 2023-11-10
It is interesting that, the code below works faster.
Not surprising. When A_aug is diagonal, expm() is the same as exp().

请先登录,再进行评论。

回答(2 个)

Star Strider
Star Strider 2023-11-10
If you want to multiply it by scalar or vector ‘t’, create an anonymous function rather than doing it symbolically —
A_aug = rand(6,6);
B_aug = rand(6,1);
M2 = @(t) expm(A_aug .* t) * B_aug;
t = 0:5;
tic
for k = 1:numel(t)
Result(:,k) = M2(t(k));
end
toc
Elapsed time is 0.064424 seconds.
format shortE
Result
Result = 6×6
1.0e+00 * 4.6155e-01 9.8985e+00 1.9054e+02 3.7164e+03 7.2586e+04 1.4178e+06 7.7791e-01 1.3078e+01 2.5333e+02 4.9457e+03 9.6600e+04 1.8869e+06 5.8940e-01 8.4603e+00 1.6211e+02 3.1618e+03 6.1750e+04 1.2061e+06 3.4496e-01 1.2376e+01 2.4938e+02 4.8821e+03 9.5378e+04 1.8630e+06 4.4668e-01 1.4365e+01 2.8701e+02 5.6118e+03 1.0962e+05 2.1412e+06 6.9777e-01 9.9196e+00 1.9076e+02 3.7249e+03 7.2760e+04 1.4212e+06
You did not post the version you are using, however this should work in all recent versions.
.
  2 个评论
Volcano
Volcano 2023-11-10
I am using 2021a. I will use expm command in SIMULINK, so cannot define a t vector. t will be updated in process.
Star Strider
Star Strider 2023-11-10
Defining it as a scalar then should work. I am not familiar with Simulink (I have it, though I have not used it in a while) however it should have the ability to evaluate ans simulate state space systems available in it, if that is what you are doing, similar to the Control System Toolbox lsim function.

请先登录,再进行评论。


Steven Lord
Steven Lord 2023-11-10
Do you absolutely need the result as a (potentially very long) symbolic expression in t, or is computing this matrix exponential-vector product numerically sufficient for your needs? If the latter, either use expm with a numeric value for t or (if you're using release R2023b or later) use expmv.
expmv can be especially useful if you could substitute specifying a vector of values for t into the numerical calculation instead of performing the calculation symbolically and then substituting numeric values, as the third input to expmv can be a vector. If the vector is equally spaced, it can use an algorithm that takes advantage of that uniformity.
  1 个评论
Volcano
Volcano 2023-11-10
编辑:Volcano 2023-11-10
I should run the expm for different t values in a process. I will perform this task in SIMULINK, so it may be useful to obtain a parametric result of matrix-exponential. Yes, the numerical t value may make the calculation faster, however my doesn't let me use pre-defined t values.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by