Unable to perform assignment because the size of the left side is 2-by-1 and the size of the right side is 2-by-2.

1 vue (au cours des 30 derniers jours)
clear all;
n = 2;
G = [2,-1;-1,2];
C = [1,0;0,1];
B = [1,0];
nd = 2;T = 10;N = 10000;
Vo = zeros(n,1);
dt = T/N;
dt1 = T/(N-1);
t(1) = 0;
for i=2:N
t(i)=(i-1)*dt1;
end
for i=1:N
Vin(i)=sin(10*t(i));
end
V(:,1) = Vo;
for i=2:N
V(:,i)=((C+G*dt))\(C*V(:,i-1)+B*Vin(i)*dt);
end
plot(t,V(nd,:));
  1 commentaire
ME
ME le 6 Déc 2019
I think some more info might be needed here.
MATLAB is correct in that your V(:,i) is going to be 2x1 and the ((C+G*dt))\(C*V(:,i-1)+B*Vin(i)*dt) is 2x2. What is it that you actually want to happen here?

Connectez-vous pour commenter.

Réponses (1)

Mahesh Taparia
Mahesh Taparia le 9 Déc 2019
Hi Mahmoud,
As per your code,
  1. V is a vector of 2X1,
  2. C and G are matrix of 2X2,
  3. B is a row vector of 1X2,
  4. dt is a scalar.
In the expression, the computation of ‘(C*V(:,i-1)+B*Vin(i)*dt)’ is not possible as per matrix multiplication rule. Also, (C+G*dt)’ will gives a 2X2 matrix and left side of equation is a vector of 2X1 dimension which is inconsistent. Check the expression or the value of the matrices you have defined.

Catégories

En savoir plus sur Matrix Indexing 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!

Translated by