Why does expm command work too slow?
12 次查看(过去 30 天)
显示 更早的评论
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 个评论
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
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
format shortE
Result
You did not post the version you are using, however this should work in all recent versions.
.
2 个评论
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
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!