# Matlab- Second moment of Area(I) Script Help!

• MATLAB
Hi,

I am in Mechanics of materials class, and I am attempting to design a cantilever beam that meets certain specifications for atomic Force microscopy. (details aren't relevant for programming steps).

I have been tasked with writing a script in matlab that:

A.) Calculates the coordinates of the centroid of any Cross section.
B.) Calculates the second moment of area (I) about the centroidal Z-axis (assume this axis is horizontal)
C.) Calculates the Q that is needed to compute the maximum shear stress.

For the above tasks, assume the resolution of the image is 1 nm/pixel.

I have already created the m-file for 1 of the images that I will be using . (it is a ring cross-section). It is attached.

I have also finished Part (A), and I think it works.

The centroid is basically the center of mass of a 2-d object.

Part B is really giving me trouble, I can't seem to make any headway towards getting the correct solution.

The equation for calculating the second moment of Area is: I=Integral(Y^2*dA) (A=area).

If someone with more programming knowledge/experience than me can help, that would be lifesaving!

The attached m files that I have finished are attached.

-Ryan
View attachment centroid2.m

View attachment ring.m

This should probably be in the Math and Scientific Software section of the CS forum. This really isn't a programming question.

Try showing us some psuedocode for what you're trying to do - I think writing this code will be easier than you think. You need to assume that each pixel has area dA. Here is a start:

Code:
for every pixel
if (is part of the object)
get distance from centroid in y-direction (you already know where "0" is...)
...
else -> do nothing
next pixel

Hope this helps,

Kerry