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

조회 수: 2 (최근 30일)
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
Ixx=((T1*T2^3)/12)+(A1*(y_bar-y1))^2+((T4*T3^3)/12)+(A2*(y2+T2-y_bar))^2;
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.

답변 (1개)

Andreas Goser
Andreas Goser 2023년 3월 14일
Could it be a need to write ".^2" rather than "^2"?
  댓글 수: 3
Alex Soles
Alex Soles 2023년 3월 14일
I have also tryed ".^3" and still have the same answer
Andreas Goser
Andreas Goser 2023년 3월 14일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by