Why does expm command work too slow?

조회 수: 11 (최근 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에서 Linear Algebra에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by