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.
조회 수: 2 (최근 30일)
이전 댓글 표시
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
ME
2019년 12월 6일
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?
답변 (1개)
Mahesh Taparia
2019년 12월 9일
Hi Mahmoud,
As per your code,
- V is a vector of 2X1,
- C and G are matrix of 2X2,
- B is a row vector of 1X2,
- 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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!