Why does expm command work too slow?
조회 수: 11 (최근 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.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!