cant mutplaye matrix by vector

조회 수: 1 (최근 30일)
tomer polsky
tomer polsky 2018년 1월 4일
편집: Guillaume 2018년 1월 4일
heloo i have this code
clc;
clear all;
R=5;
C=100e-6;
L=10e-3;
U=5;
A=[0 1/C;-1/L -R/L];
x=[0;0];
t=linspace(0,0.5,4);
t_delta=t(2)-t(1);
x_0=[0;0];
for i=1:length(t)
x(:,i+1)=t(i)*A
end
i have this code and i want to multipay A by t,but i get this eror: Assignment has more non-singleton rhs dimensions than non-singleton subscripts
how do i fix it ?
  댓글 수: 2
Jan
Jan 2018년 1월 4일
편집: Jan 2018년 1월 4일
There is no "b" in your code. Which vector do you want to multiply with which matrix? What is the meaning of x1 and x_0?
Guillaume
Guillaume 2018년 1월 4일
how do i fix it ?
We don't know since we have no idea what you're trying to do.
t(i)*A results in a 2x2 matrix that you're trying to put in a 2x1 section of a matrix. That's never going to work.
In addition, as commented in your previous question, growing the x matrix is a bad idea. In this particular case, it's not even clear that the loop is needed.

댓글을 달려면 로그인하십시오.

답변 (2개)

Jan
Jan 2018년 1월 4일
Your A is 2x2 matrix and x is a 2x1 vector. Then:
x(:,i+1)=t(i)*A
has a 2x2 matrix on the right and a 2x1 vector on the left side.
It is not clear what you want to calculate. Start with writing it down with pencil and paper. Then create a clear an meaningful comment in the code, which explains, what you want to achieve. Afterwards writing the code (or suggesting an improvement) is much easier.
  댓글 수: 4
tomer polsky
tomer polsky 2018년 1월 4일
ok i am sorry for the mess, so as i said i want to mulyipliey t(i) by A, i need to get vecotr of 2x1 ; becouse I need to get vecotr in the size of 2x1 for each i , and then multiplay this vector by vecotr A that his size is 2x2
Jan
Jan 2018년 1월 4일
t(i) is a scalar, A is a 2x2 matrix. Multiplying them creates a 2x2 matrix. If you state, that you want to get a 2x1 vector, a multiplication is not the right operation.

댓글을 달려면 로그인하십시오.


Star Strider
Star Strider 2018년 1월 4일
If you are doing a state-space simulation, you are doing it incorrectly. You need to use a matrix exponential (the expm function), with the correct matrix multiplications.
See if this does what you want:
for i=1:length(t)
x(:,i) = expm(t(i)*A) * [1; 1] + x_0
end
You need to include the ‘A’, ‘B’, and ‘C’ matrices. (I created ‘B’ as [1;1] to produce a column vector output for ‘x’. Use your own matrices in the calculation.)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by