Error with matrix calculation

5 次查看(过去 30 天)
Tobias
Tobias 2024-5-2
评论: Tobias 2024-5-3
% 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 个评论
Tobias
Tobias 2024-5-3
I forgot a row with values in M3, but it still doesnt work. M3 is now 12 12, and N3 is 12 1

请先登录,再进行评论。

回答(2 个)

James Tursa
James Tursa 2024-5-2
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
Walter Roberson 2024-5-3
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.

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by