Error with matrix calculation
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
% matrix calculation
M3 = [0 0 0 0 -1 0 0 0 0 0 1 0;
0 0 0 0 0 1 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 -0.05 1;
1 0 0 0 0 0 0 0 -1 0 -1 0;
0 -1 0 0 0 0 0 0 0 -1 0 0;
-0.15 0 0 0 0 0 0 0 -0.15 0 0.05 0;
-1 0 1 0 0 0 0 0 0 0 0 0;
0 1 0 1 0 0 0 0 0 0 0 0;
-0.4*sind(20) -0.4*cosd(20) -0.4*sind(20) 0.4*cosd(20) 0 0 0 0 0 0 0 0;
0 0 0 -1 0 0 0 1 0 0 0 0;
0 0 (BD/2)*cosd(Angle_FBD) (BD/2)*sind(Angle_FBD) 0 0 (BD/2)*cosd(Angle_FBD) (BD/2)*sind(Angle_FBD) 0 0 0 0];
N3 = [mass_body1*Acceleration_G1x;
mass_body1*Acceleration_G1y+mass_body1*9.81;
mass_body1*radius_body1^2*alpha_1;
mass_body2*Acceleration_G2x;
mass_body2*Acceleration_G2y+mass_body2*9.81;
(1/12)*mass_body2*radius_body2^2*alpha_2;
mass_body3*Acceleration_G3x;
mass_body3*Acceleration_G3y+mass_body3*9.81;
(1/12)*mass_body3*radius_body3^2*alpha_3;
mass_body4*Acceleration_G4x;
mass_body4*Acceleration_G4y+mass_body4*9.81;
(1/12)*mass_body4*BD^2*alpha_4];
X = M3/N3
It says that there is an error using "/" and that matrix dimensions must agree. I dont know exactly what this means, and can't find where the issue is. The error is in the line "X = M3/N3"
4 commentaires
Réponses (2)
James Tursa
le 2 Mai 2024
We don't have all the variables necessary to run your code, but guessing that maybe you need element-wise divide instead of matrix divide?
X = M3 ./ N3
Note the period, so try ./ instead of just /
Walter Roberson
le 3 Mai 2024
When you use the / (matrix right divide) operator, the two operands must have the same number of columns. The resulting matrix will have a size that is the number of rows of the first operand, by the number of rows of the second operand.
A = rand(5,3); B = rand(7,3);
A / B
You appear to be constructing an 11 x 12 matrix and dividing it by a 12 x 1 matrix. None of the operators \ .\ / or ./ would be suitable for that purpose.
It would not be an error to calculate
X = M3/N3'
which would then be an 11 x 12 matrix divided by a 1 x 12 matrix, which would give an 11 x 1 result.
0 commentaires
Voir également
Catégories
En savoir plus sur Matrix Indexing 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!