Effacer les filtres
Effacer les filtres

Error with matrix calculation

5 vues (au cours des 30 derniers jours)
Tobias
Tobias le 2 Mai 2024
Commenté : Tobias le 3 Mai 2024
% 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
Tobias
Tobias le 3 Mai 2024
M3 is A and N3 is B
Tobias
Tobias le 3 Mai 2024
I forgot a row with values in M3, but it still doesnt work. M3 is now 12 12, and N3 is 12 1

Connectez-vous pour commenter.

Réponses (2)

James Tursa
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 /
  1 commentaire
Tobias
Tobias le 3 Mai 2024
thanks, it worked!

Connectez-vous pour commenter.


Walter Roberson
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
ans = 5x7
0 0 0 0 1.8427 1.2240 -0.1906 0 0 0 0 -0.3170 0.8279 0.7349 0 0 0 0 1.1372 0.7934 0.5501 0 0 0 0 0.2419 1.0085 -0.2503 0 0 0 0 0.2136 1.2041 -0.0009
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
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.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by