cant mutplaye matrix by vector

1 view (last 30 days)
tomer polsky
tomer polsky on 4 Jan 2018
Edited: Guillaume on 4 Jan 2018
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 Comments
Jan
Jan on 4 Jan 2018
Edited: Jan on 4 Jan 2018
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 on 4 Jan 2018
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.

Sign in to comment.

Answers (2)

Jan
Jan on 4 Jan 2018
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 Comments
tomer polsky
tomer polsky on 4 Jan 2018
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 on 4 Jan 2018
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.

Sign in to comment.


Star Strider
Star Strider on 4 Jan 2018
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.)

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!