How to find volume under fitted data?

I have a set of data, fitted by polynomial of 8th order. I want to find the volume under this surface (due to rotation around y axis for example). I am not sure how to do it. Should I use dblquad or trapz? Since dblquad needs function handle and I do not have the function, just the interpolated data (I also can not use interp2 (as suggested in some answers), because it uses linear interpolation. Any idea how I can find the volume?
Thank you!

3 Comments

YOu want a area or volume? I think it is area.....
No. I want the volume resulted from the revolution of this plot (say, half of it) around y axis which gives a spherical shape. Thank you
Go ahead with trapz.

Sign in to comment.

 Accepted Answer

Teja Muppirala
Teja Muppirala on 28 Sep 2017
Edited: Teja Muppirala on 28 Sep 2017
If you have a function y = f(r), which it sounds like you do since you have a polynomial, then you can use integral.
y = @(r) 1-r; % y can be any arbitrary function of r. Put the function for your curve here (POLYVAL?).
a = 0; % Some limits of integration r = a to b
b = 1;
% Volume under surface of rotation:
vol = 2*pi*integral(@(r) y(r) .* r, a, b) % Put in the extra ".*r" for polar coords.
Here I used y = 1-r, so it is a cone, and I can verify that the answer I got (vol=1.047) was indeed equal to the analytical answer for the volume of a cone with unit height and radius (pi/3).
If you don't have a function, but just some discrete set of values r and y, then you can use INTERP1 along with INTEGRAL.
r = [ 0 0.2 0.4 0.6 0.8 1.0 ]; % Again, just use a unit cone for testing purposes
y = [ 1 0.8 0.6 0.4 0.2 0 ];
Yfun = @(p) interp1(r, y, p);
vol = 2*pi*integral(@(r) Yfun(r).*r, 0, 1) % Again, you'll get 1.0472

8 Comments

Thank you.
Torsten
Torsten on 28 Sep 2017
Edited: Torsten on 28 Sep 2017
This is rotation around the x-axis, not the y-axis.
Best wishes
Torsten.
Does it make any difference in calculating the volume?
Thank you
Torsten
Torsten on 28 Sep 2017
Edited: Torsten on 28 Sep 2017
Sure.
Imagine a half-circle centered at 0.
Rotation about the x-axis gives you the volume of a full sphere while rotation about the y-axis gives you the volume of a half-sphere.
Best wishes
Torsten.
Hi. I rechecked this and I don't think I made a mistake. We can test it.
Let's take a line with slope -1/2.
y = @(r) 1-0.5*r; % Line
a = 0; % Some limits of integration r = a to b
b = 2;
Rotation around the y-axis gives a "fat cone" with radius 2 and height 1. Rotation around x-axis gives a "skinny cone" pointing right, with radius 1 and height 2.
Volume around y should be 1/3*pi*r^2*h = 1/3*pi*(2^2)*1 = 4.1888
Volume around x should be 1/3*pi*(1^2)*2 = 2.0944.
vol_around_y = 2*pi*integral(@(r) y(r) .* r, a, b) % Rotation around y-axis
vol_around_x = pi*integral(@(r) y(r).^2 , a, b) % Rotation around x-axis is given by this
We can confirm:
vol_around_y =
4.1888
vol_around_x =
2.0944
Steven
Steven on 29 Sep 2017
Edited: Steven on 29 Sep 2017
Thank you guys. Since I want the rotation of the right-half of the plot around y axis, I would use Teja's first formula. Although I don't understand that .*r multiplication in the formula for polar coordinates. So in this case, we are integrating the area of a cylinder over height? Thanks
Torsten
Torsten on 29 Sep 2017
Edited: Torsten on 29 Sep 2017
Teja is right - sorry for the confusion.
The formula says that the volume of the surface of revolution around the y-axis is obtained by integrating the lateral surface area A(x) of the cylinders which you get when you rotate a vertical line from the x-axis up to your polynomial function around the y-axis ( which is A(x) = 2*pi*x*P(x) ).
Best wishes
Torsten.
Thanks Torsten

Sign in to comment.

More Answers (0)

Asked:

on 28 Sep 2017

Commented:

on 29 Sep 2017

Community Treasure Hunt

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

Start Hunting!