I am unsure why my MATLAB code is causing errors and not matching hand calculations?

5 vues (au cours des 30 derniers jours)
Alex Soles
Alex Soles le 14 Mar 2023
Commenté : Andreas Goser le 14 Mar 2023
Hand calculation is:
(125*25^3/12+125*25*(52.7-12.5))^2 + (15*160^3/12+15*160*(80+25-52.7))^2
ans = 2.7599e+13
= 16897581.42 or 1.69x10^7mm^4
MATLAB code error
% Dimensions of T-beam
T1 = 125; % Width of flange
T2 = 25; % Width of web
T3 = 160; % Thickness of flange
T4 = 15; % Height of web
T5 = 40; % Distance to K
% Compute the area and first moment of area for each rectangular section
A1 = T1*T2;
y1 = T2/2;
AM1 = A1*y1;
A2 = T3*T4;
y2 = T3/2;
AM2 = A2*y2+T2;
% Compute the total area and first moment of area
A = A1 + A2;
AM = AM1 + AM2;
% Compute the centroid location in the x & y direction
y_bar = ((A1*(y1))+(A2*((y2)+T2)))/((A1)+(A2));
x_bar = T1/2;
% Moment of Inertia
fprintf('The Moment of Inertia is %s mm^4.\n',Ixx);
The Moment of Inertia is 3.153873e+10 mm^4.
Incorrect - should be 16897581 or 1.69x10^7 as per word calc? - Error in the main Moment of inertia code.

Réponses (1)

Andreas Goser
Andreas Goser le 14 Mar 2023
Could it be a need to write ".^2" rather than "^2"?
  3 commentaires
Andreas Goser
Andreas Goser le 14 Mar 2023
Me recommendation is to make the comparison step-by-step so you can see in which calculation the issue occurs. It also helpt to share the full code again once you made an edit.
I just noticed the .^2 vs °2 as this can happen with beginnners. Also ./ vs. / is a frequent issue.

Connectez-vous pour commenter.


En savoir plus sur Graphics 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!

Translated by