# Centroid calculation using integrals

• arhzz
In summary, the author is given a function and is supposed to find the centroid of the function. However, the author has problems understanding the function and is not sure how to calculate the area under the curve.

#### arhzz

Homework Statement
Find xs and ys
Relevant Equations
Integration
Hello!

Im given this function ## f:[-\pi/2,1] -> [0,1]## with f(x) = 1-x for x (0,1] and f(x) = cos(x) for x ##[-\pi/2,0] ##

And im susposed to find the centroid of this function so xs and ys.

For that I am given these 2 equations ( I found them in the notes)

## x_s =\frac{1}{A} \int_{a}^{b} f(x) x dx ## and ##y_s =\frac{1}{A} \int_{a}^{b} \frac{f(x)}{2}*f(x) dx##

Now to calculate A I found this formula ## A = \int_{a}^{b} f(x) dx ##

Okay so now looking at my problem specificly I have 2 diffrent values for the function depending on where it is. So I calculated A1 and A2; one for 1-x with the integral bounderies going from 0 to 1 and A2 for cos(x) with integral bounderies being -pi/2 and 1

I get ## A_1= \frac{1}{2} ## and ##A_2 = 1 ## Think that should be correct. Now since I have 2 A's (A should be the surface) I went ahead and caluclated using the formulas I posted above xs1 and xs2. For xs1 I used A1 and the same integral bounderies (0 to 1); for xs2 I used A2 and -pi/2 to 1

I get ##xs_1 = \frac{1}{3} ## and ##xs_2 = 1 - \frac{\pi}{2} ## Okay now to get a final xs I tried adding xs1 and xs2 together

After doing that i get this ##x_s =\frac{8-3\pi}{6} ## for xs. The solution says it should be ##xs = \frac{7-3\pi}{9} ##

I have rechecked all of my integrals and they should be correct,so im making a mistake somewhere else.I am not to sure what to do when I have 2 xs's, can i just add them together or not? Am i choosing the integral bounderies correctly or not?

Last edited:
arhzz said:
Im given this function ## f:[-\pi/2,1] -> [0,1]## with f(x) = 1-x for x (0,1] and f(x) = cos(x) for x ##[-\pi/2,1] ##
For the above function, I think that for the 2nd part of your function the definition should be ##f(x) = \cos(x)## for ##x \in [\frac{-\pi}2, 0]##.

I'll take a look at the rest of your work and reply on it later.

arhzz said:
Okay so now looking at my problem specificly I have 2 diffrent values for the function depending on where it is. So I calculated A1 and A2; one for 1-x with the integral bounderies going from 0 to 1 and A2 for cos(x) with integral bounderies being -pi/2 and 1
This is the source of your problems. If I am correct in what I wrote in the previous post, the interval for the f(x) = cos(x) part should be ##[-\pi/2, 0]##, not ##[\pi/2, 1]##. With the intervals you wrote, you'll get two different function values on the interval [0, 1], so you'll get the wrong values for the area beneath the cos(x) part as well as the moment about the y-axis, which you're calling xs.
arhzz said:
I get ## A_1= \frac{1}{2} ## and ##A_2 = 1 ## Think that should be correct.
I get the same values for the two areas. Was this your integral for ##A_2##: ##\int_{-\pi/2}^0~\cos(x)dx##? If so, you are using the correct interval; namely ##[-\pi/2, 0]##.

You don't show the work you did for what you're calling xs (the moment about the y-axis). If you use the wrong interval for this integral, you'll get a wrong value.

Also for what you're calling ys, the moment about the x-axis, you'll need to use ##\cos^{-1}(x)## in the integrand, with the limits of integration being 0 and 1.

Mark44 said:
This is the source of your problems. If I am correct in what I wrote in the previous post, the interval for the f(x) = cos(x) part should be ##[-\pi/2, 0]##, not ##[\pi/2, 1]##. With the intervals you wrote, you'll get two different function values on the interval [0, 1], so you'll get the wrong values for the area beneath the cos(x) part as well as the moment about the y-axis, which you're calling xs.

I get the same values for the two areas. Was this your integral for ##A_2##: ##\int_{-\pi/2}^0~\cos(x)dx##? If so, you are using the correct interval; namely ##[-\pi/2, 0]##.

You don't show the work you did for what you're calling xs (the moment about the y-axis). If you use the wrong interval for this integral, you'll get a wrong value.

Also for what you're calling ys, the moment about the x-axis, you'll need to use ##\cos^{-1}(x)## in the integrand, with the limits of integration being 0 and 1.
Oh I just checked I made a mistake in the original post. The interval you posted is correct and that is the one I used; A2 you just typed in. I will edit my post.

Although I typed it in the forum wrong I calculated with the right intervals; hence you get the same area under the curve. The rest what I did is I just pluged in the formula. I can post it in detail if it will help.

arhzz said:
The rest what I did is I just pluged in the formula. I can post it in detail if it will help.
Yes, please post your integrals for xs and ys. If you click on the integral I wrote you can see the Tex that I wrote for it.

Okay here we go

$$x_s1 = \frac{1}{A1} \int_{0}^{1} xf(x)dx$$ With plug in values $$x_s1 = \frac{1}{1/2} \int_{0}^{1} (1-x) * x dx$$

Multiply the brackets out and get rid of the double fraction $$2 * \int_{0}^{1} x^2 - x dx$$ Now solve the Integral, it should be only the power rule so we get $$2 * ( \frac{x^2}{2} - \frac{x^3}{3})$$ And I dont know how to do it in LaTeX but evalute the brackets at 1 and 0. Now I put the bracket term on a common denominator and get this $$2*(\frac{3x^2-2x^3}{6})$$ So now we have to plug in 1 into x and subtract that from plugging 0 into x. If we plug 1 into this we get 1/6, if we plug 0 we get 0 hence we are left with. $$2 * \frac{1}{6}$$ and that is 1/3.

Okay for xs2 =$$1 * \int_{-pi/2}^{0} xcos(x) dx$$ Use partiall integration to solve the integral; I get $$1* (xsin(x)+cos(x))$$ and evaluate at -pi/2 and 0. Plug in first 0 than -pi/2 and subract them from each other.We should get $$1*(1-\frac{pi}{2} )$$.

This is how I did it

That doesn't look right to me.

The moment about the y-axis, which you have separated into s1 and s2 has to be done as a single quantity. You can't do them separately.

This is what you need. $$\overline x = \frac{M_{y, 1} + M_{y, 2}}{A_1 + A_2} = \frac{\int_{-\pi/2}^0~x\cos(x)dx + \int_0^1 ~x(1 - x)dx}{A_1 + A_2}$$

Your values for the two integrals look ok to me, but you can't calculate the two parts of this moment separately.

The value I get for ##\overline x = \frac{M_y}{A_1}##, the x-coordinate of the centroid, is ##1 - \frac \pi 3##. I don't guarantee that I haven't made any mistakes.

Calculating ##M_x## will be a bit harder, but you need it to get the other coordinate of the centroid, ##\overline y##.

arhzz
Mark44 said:
That doesn't look right to me.

The moment about the y-axis, which you have separated into s1 and s2 has to be done as a single quantity. You can't do them separately.

This is what you need. $$\overline x = \frac{M_{y, 1} + M_{y, 2}}{A_1 + A_2} = \frac{\int_{-\pi/2}^0~x\cos(x)dx + \int_0^1 ~x(1 - x)dx}{A_1 + A_2}$$

Your values for the two integrals look ok to me, but you can't calculate the two parts of this moment separately.

The value I get for ##\overline x = \frac{M_y}{A_1}##, the x-coordinate of the centroid, is ##1 - \frac \pi 3##. I don't guarantee that I haven't made any mistakes.

Calculating ##M_x## will be a bit harder, but you need it to get the other coordinate of the centroid, ##\overline y##.
Ahh okay that makes sence.See I did not know this formula existed, and I knew I was calculating the integrals right. So if I understood you correctly this will give me the value of my xs? So for ys I need to the same but solve a trickier integral?

arhzz said:
Ahh okay that makes sence.See I did not know this formula existed, and I knew I was calculating the integrals right. So if I understood you correctly this will give me the value of my xs? So for ys I need to the same but solve a trickier integral?
Yes.

arhzz
Okay I finally got around to revisiting this.And you are right,the formula was wrong. Using the formula you gave me the right result (the result I was not been able to find in post #1). Thank you for your great help as always!

## 1. What is a centroid?

A centroid is the center of mass of an object or shape. It is the point where the object would balance if it were placed on a needle or a sharp point.

## 2. How is the centroid calculated using integrals?

The centroid of a shape can be calculated by dividing the shape into infinitesimally small rectangles, finding the area of each rectangle using integrals, and then taking the weighted average of the x and y coordinates of each rectangle's centroid.

## 3. Why is it important to calculate the centroid of a shape?

The centroid of a shape is important because it helps determine the overall balance and stability of the shape. It is also used in various engineering and scientific applications, such as determining the center of mass for designing structures and calculating moments of inertia.

## 4. Can the centroid be outside of the shape?

No, the centroid is always located within the boundaries of the shape. This is because the centroid is calculated by taking the weighted average of the x and y coordinates of the shape's infinitesimally small rectangles, which are all located within the shape.

## 5. Are there any other methods for calculating the centroid of a shape?

Yes, there are other methods for calculating the centroid, such as using geometric properties or using the parallel axis theorem. However, the method of using integrals is the most widely used and accurate method for calculating the centroid of a shape.