Solving the matrix dimention for expm function

Good afternoon,
I and working in the code bellow. I have an error message Arrays have incompatible sizes for this operation.
time=0:0.01:2*pi; %time vector
H=[0 1 0 0 0;1 0 0 0 0;0 0 1 0 1;0 0 0 1 1;0 0 1 1 0];
B = [2 ;-2 ];
C=[0.1 + 0.010i;0.2 + 0.0010i; 0.1 + 0.0020i;-0.4 + 0.001i;0.8 - 0.7i];
for k1 = 1:numel(time)
y(:,k1) = expm(H*time(k1))*C.*B;
end
figure(1)
plot(time,y)
grid
I really appreciate any help and suggestions

4 commentaires

Torsten
Torsten le 25 Mai 2021
expm(H*time(k1)) is 5x5
C is 5x1,
so expm(H*time(k1))*C is 5x1.
So B had to be 5x1 instead of 2x1.
Dear @Torsten thank you for your reply. yes that exactly the problem. I am wondering if you have any suggestion how to it.
I changed the size of B to 5x1 but the problem still there as I need to change also C to 5x5.
Torsten
Torsten le 25 Mai 2021
If B is 5x1,
y(:,k1) = (expm(H*time(k1))*C).*B
should work.
@Torsten Really appreciate that from you.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur MATLAB dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by