cant mutplaye matrix by vector
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Guillaume
le 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.
Réponses (2)
Jan
le 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 commentaires
Jan
le 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.
Star Strider
le 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.)
0 commentaires
Voir également
Catégories
En savoir plus sur Logical 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!