Matrix dimension must agree

1 vue (au cours des 30 derniers jours)
Maria Makri
Maria Makri le 13 Oct 2019
S=[1/2 8/10 9/10 1]
g=[1/18 1/4/12/9.5 1/29/12]
L=[S(1)-g(1) 0 1/(4*12) 0; g(1) S(2)-g(2) S(3)-g(3) 0; 0 0 g(3) S(4)]
t=1:4;
n=zeros(length(t),4);
n(1,:) = [100; 80; 100; 50];
t_final=200;
for i=1:t_final
n(i+1,:) = L.*n(i,:)';
end
Ι want to construct a Leslie matrix in matlab but when I multiply the n vector with the Matrix I keep getting this : Matrix dimensions must agree. I don't know how to fix it.
  1 commentaire
Walter Roberson
Walter Roberson le 13 Oct 2019
L is a 3 x 4 matrix. You are using .* against a 4 x 4 extracted down to 1 x 4 and then transposed to get a 4 x 1. What result are you expecting from using a 3 x 4 .* a 4 x 1 ?

Connectez-vous pour commenter.

Réponses (1)

Prateekshya
Prateekshya le 20 Août 2024
Hi Maria,
The error you are encountering is due to the incorrect use of element-wise multiplication (.*) instead of matrix multiplication (*). In MATLAB, when you want to multiply a matrix by a vector using matrix multiplication, you should use the "*" operator. Please refer to the below link for more information on Matrix Multiplication in MATLAB: https://www.mathworks.com/help/matlab/ref/mtimes.html
I hope this helps!

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by