cant mutplaye matrix by vector

2 次查看(过去 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 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by