Why does expm command work too slow?
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Matt J
le 10 Nov 2023
It is interesting that, the code below works faster.
Not surprising. When A_aug is diagonal, expm() is the same as exp().
Réponses (2)
Star Strider
le 10 Nov 2023
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 commentaires
Star Strider
le 10 Nov 2023
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
le 10 Nov 2023
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 commentaire
Voir également
Catégories
En savoir plus sur Linear Algebra dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!