Thread Subject: n-dimensional sphere cap volume

Subject: n-dimensional sphere cap volume

From: Berlioz Berlioz

Date: 3 Feb, 2008 00:54:01

Message: 1 of 13

Hi folk!

could somebody point me to a reference for the volume of a
sphere cap in n>3 dimensions?

I'm wondering if an exact formula does exist; I googled but
I found only lower and upper boundings

Many thanks
edo

Subject: n-dimensional sphere cap volume

From: Roger Stafford

Date: 3 Feb, 2008 05:57:01

Message: 2 of 13

"Berlioz Berlioz" <speedo77@email.it> wrote in message <fo33b9$hmj
$1@fred.mathworks.com>...
> Hi folk!
>
> could somebody point me to a reference for the volume of a
> sphere cap in n>3 dimensions?
>
> I'm wondering if an exact formula does exist; I googled but
> I found only lower and upper boundings
>
> Many thanks
> edo
----------
  I cannot give you a simple closed solution in terms of general n. It is
possible there is no such thing. Here is as far as I can get. Referring to the
Mathworld site at

 http://mathworld.wolfram.com/Hypersphere.html

the volume (content) of a hypersphere of radius R in n dimensions is

 V_n(R) = 2*pi^(n/2)/n/gamma(n/2)*R^n

If we use "cross sections" orthogonal to the central axis, x, of the cap and
integrate along this x axis, the "area" of each section will be the content of an
n-1 dimensional sphere of radius sqrt(R^2-x^2). This gives an integral of:

 int('V_n-1(sqrt(R^2-x^2),'x',R-h,R)

where h is the height of the cap. Substituting x = R*cos(t), we get

 2*pi^((n-1)/2)/(n-1)/gamma((n-1)/2)*R^n*int('sin(t)^n','t',0,s)

where s = acos((R-h)/R).

  Here is where the progress stops. I know of no general expression in terms
of n for the integral of sin(t)^n. Integral tables have an iterative formula that
can be used repetitively for any particular value of n which is derived from
performing integration by parts, but no general compact formula. I suspect
none exists, but I am not certain of this. The iteration formula is:

 int('sin(t)^n','t') =
 -sin(t)^(n-1)*cos(t)/n+(n-1)/n*int('sin(t)^(n-2)','t')

For example, for n = 7, matlab yields an answer of

 -1/7*sin(t)^6*cos(t)-6/35*sin(t)^4*cos(t) ...
 -8/35*sin(t)^2*cos(t)-16/35*cos(t)

but the larger the integer n, the more terms in the expression.

  In other words, for any specific value of n, one can always obtain an exact
formula for the cap's content in terms of R and h, but for each higher value of
n the formula becomes longer and requires more computation.

Roger Stafford

Subject: n-dimensional sphere cap volume

From: John D'Errico

Date: 3 Feb, 2008 12:11:02

Message: 3 of 13

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in
message <fo3l3d$7rb$1@fred.mathworks.com>...
> "Berlioz Berlioz" <speedo77@email.it> wrote in message <fo33b9$hmj
> $1@fred.mathworks.com>...
> > Hi folk!
> >
> > could somebody point me to a reference for the volume of a
> > sphere cap in n>3 dimensions?
> >
> > I'm wondering if an exact formula does exist; I googled but
> > I found only lower and upper boundings
> >
> > Many thanks
> > edo
> ----------
> I cannot give you a simple closed solution in terms of general n. It is
> possible there is no such thing. Here is as far as I can get. Referring to the
> Mathworld site at
>
> http://mathworld.wolfram.com/Hypersphere.html
>
> the volume (content) of a hypersphere of radius R in n dimensions is
>
> V_n(R) = 2*pi^(n/2)/n/gamma(n/2)*R^n
>
> If we use "cross sections" orthogonal to the central axis, x, of the cap and
> integrate along this x axis, the "area" of each section will be the content of
an
> n-1 dimensional sphere of radius sqrt(R^2-x^2). This gives an integral of:
>
> int('V_n-1(sqrt(R^2-x^2),'x',R-h,R)
>
> where h is the height of the cap. Substituting x = R*cos(t), we get
>
> 2*pi^((n-1)/2)/(n-1)/gamma((n-1)/2)*R^n*int('sin(t)^n','t',0,s)
>
> where s = acos((R-h)/R).
>
> Here is where the progress stops. I know of no general expression in
terms
> of n for the integral of sin(t)^n. Integral tables have an iterative formula
that
> can be used repetitively for any particular value of n which is derived from
> performing integration by parts, but no general compact formula. I suspect
> none exists, but I am not certain of this. The iteration formula is:
>
> int('sin(t)^n','t') =
> -sin(t)^(n-1)*cos(t)/n+(n-1)/n*int('sin(t)^(n-2)','t')
>
> For example, for n = 7, matlab yields an answer of
>
> -1/7*sin(t)^6*cos(t)-6/35*sin(t)^4*cos(t) ...
> -8/35*sin(t)^2*cos(t)-16/35*cos(t)
>
> but the larger the integer n, the more terms in the expression.
>
> In other words, for any specific value of n, one can always obtain an exact
> formula for the cap's content in terms of R and h, but for each higher value
of
> n the formula becomes longer and requires more computation.
>
> Roger Stafford

Roger, these were pretty much the conclusions I'd
drawn last night too. I don't see anything past your
statements, except for the idea that a recursive
expression for the integral is still a valid method
for evaluating that expression, once n is fixed.

John

Subject: n-dimensional sphere cap volume

From: Roger Stafford

Date: 3 Feb, 2008 14:42:02

Message: 4 of 13

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <fo4b0m
$or5$1@fred.mathworks.com>...
> Roger, these were pretty much the conclusions I'd
> drawn last night too. I don't see anything past your
> statements, except for the idea that a recursive
> expression for the integral is still a valid method
> for evaluating that expression, once n is fixed.
>
> John
--------
  You're quite right, John. I cast too pessimistic a spell on the solution when I
pronounced "here is where the progress stops." Perhaps I had worked on it
too late at night. In fact, in that derivation is contained the outline of the
complete solution to the problem for any n. The only undesirable aspect of it
is that, as you say, it must be derived recursively. A matlab function could
readily be written to carry this out, using recursion of course.

  Apparently this has already been done in Fortran by an Arthur Stroud at the
website

 <http://people.scs.fsu.edu/~burkardt/f_src/stroud/stroud.html>

which states that "STROUD is a library of FORTRAN90 routines, using double
precision arithmetic, which implement multidimensional quadrature rules of
Arthur Stroud" and possesses a routine called "SPHERE_CAP_VOLUME_ND"
which is said to compute "the volume of a spherical cap in ND." (There is also
a matlab Stroud library but I don't see an n-dimensional spherical cap volume
function in it.)

Roger Stafford

Subject: n-dimensional sphere cap volume

From: Berlioz Berlioz

Date: 3 Feb, 2008 15:16:02

Message: 5 of 13

I want to thank you for the really complete answer that was
really helpfull to me.

If somebody is intereseted I can post the bounding limits
for the volume of hyperspherical cap or radius R and height
h. I think this is the only way to compute it when n tend to
infinite because the recurisve formula has really many
terms. But as the volume of the hypersphere tends to zero
when n --> oo I think also that the volume tends to zero

again many thanks
edoardo


"John D'Errico" <woodchips@rochester.rr.com> wrote in
message <fo4b0m$or5$1@fred.mathworks.com>...
> "Roger Stafford"
<ellieandrogerxyzzy@mindspring.com.invalid> wrote in
> message <fo3l3d$7rb$1@fred.mathworks.com>...
> > "Berlioz Berlioz" <speedo77@email.it> wrote in message
<fo33b9$hmj
> > $1@fred.mathworks.com>...
> > > Hi folk!
> > >
> > > could somebody point me to a reference for the volume of a
> > > sphere cap in n>3 dimensions?
> > >
> > > I'm wondering if an exact formula does exist; I
googled but
> > > I found only lower and upper boundings
> > >
> > > Many thanks
> > > edo
> > ----------
> > I cannot give you a simple closed solution in terms of
general n. It is
> > possible there is no such thing. Here is as far as I
can get. Referring to the
> > Mathworld site at
> >
> > http://mathworld.wolfram.com/Hypersphere.html
> >
> > the volume (content) of a hypersphere of radius R in n
dimensions is
> >
> > V_n(R) = 2*pi^(n/2)/n/gamma(n/2)*R^n
> >
> > If we use "cross sections" orthogonal to the central
axis, x, of the cap and
> > integrate along this x axis, the "area" of each section
will be the content of
> an
> > n-1 dimensional sphere of radius sqrt(R^2-x^2). This
gives an integral of:
> >
> > int('V_n-1(sqrt(R^2-x^2),'x',R-h,R)
> >
> > where h is the height of the cap. Substituting x =
R*cos(t), we get
> >
> >
2*pi^((n-1)/2)/(n-1)/gamma((n-1)/2)*R^n*int('sin(t)^n','t',0,s)
> >
> > where s = acos((R-h)/R).
> >
> > Here is where the progress stops. I know of no
general expression in
> terms
> > of n for the integral of sin(t)^n. Integral tables have
an iterative formula
> that
> > can be used repetitively for any particular value of n
which is derived from
> > performing integration by parts, but no general compact
formula. I suspect
> > none exists, but I am not certain of this. The
iteration formula is:
> >
> > int('sin(t)^n','t') =
> > -sin(t)^(n-1)*cos(t)/n+(n-1)/n*int('sin(t)^(n-2)','t')
> >
> > For example, for n = 7, matlab yields an answer of
> >
> > -1/7*sin(t)^6*cos(t)-6/35*sin(t)^4*cos(t) ...
> > -8/35*sin(t)^2*cos(t)-16/35*cos(t)
> >
> > but the larger the integer n, the more terms in the
expression.
> >
> > In other words, for any specific value of n, one can
always obtain an exact
> > formula for the cap's content in terms of R and h, but
for each higher value
> of
> > n the formula becomes longer and requires more computation.
> >
> > Roger Stafford
>
> Roger, these were pretty much the conclusions I'd
> drawn last night too. I don't see anything past your
> statements, except for the idea that a recursive
> expression for the integral is still a valid method
> for evaluating that expression, once n is fixed.
>
> John

Subject: n-dimensional sphere cap volume

From: Berlioz Berlioz

Date: 3 Feb, 2008 15:21:04

Message: 6 of 13

Last night I browsed the STROUD library but like you I didnt
find a function to compute that in the library so I wrote a
post here.

I found a such function on another website that seems to be
related to STROUD libray but it was quite obscure to me.



In fact, in that derivation is contained the outline of the
> complete solution to the problem for any n. The only
undesirable aspect of it
> is that, as you say, it must be derived recursively. A
matlab function could
> readily be written to carry this out, using recursion of
course.
>
> Apparently this has already been done in Fortran by an
Arthur Stroud at the
> website
>
>
<http://people.scs.fsu.edu/~burkardt/f_src/stroud/stroud.html>
>
> which states that "STROUD is a library of FORTRAN90
routines, using double
> precision arithmetic, which implement multidimensional
quadrature rules of
> Arthur Stroud" and possesses a routine called
"SPHERE_CAP_VOLUME_ND"
> which is said to compute "the volume of a spherical cap in
ND." (There is also
> a matlab Stroud library but I don't see an n-dimensional
spherical cap volume
> function in it.)
>
> Roger Stafford
>

Subject: n-dimensional sphere cap volume

From: John D'Errico

Date: 3 Feb, 2008 16:05:06

Message: 7 of 13

"Berlioz Berlioz" <speedo77@email.it> wrote in message
<fo4m50$pii$1@fred.mathworks.com>...
> Last night I browsed the STROUD library but like you I didnt
> find a function to compute that in the library so I wrote a
> post here.
>
> I found a such function on another website that seems to be
> related to STROUD libray but it was quite obscure to me.

I'll write a code to put on the file exchange,
if you will find that useful.

John

Subject: n-dimensional sphere cap volume

From: Berlioz Berlioz

Date: 3 Feb, 2008 16:27:02

Message: 8 of 13

Many thanks I'am already working on this, but once u have
the recurisve formula that it is pretty easy!.

I think that the integral of (sint).^n can be easily
computed using standard (quad, etc..) matlab integration
instead of using the exact recursive formula.
By the I'm working on a 20 dimensional space

all the best
edoardo


"John D'Errico" <woodchips@rochester.rr.com> wrote in
message <fo4oni$o8j$1@fred.mathworks.com>...
> "Berlioz Berlioz" <speedo77@email.it> wrote in message
> <fo4m50$pii$1@fred.mathworks.com>...
> > Last night I browsed the STROUD library but like you I didnt
> > find a function to compute that in the library so I wrote a
> > post here.
> >
> > I found a such function on another website that seems to be
> > related to STROUD libray but it was quite obscure to me.
>
> I'll write a code to put on the file exchange,
> if you will find that useful.
>
> John

Subject: n-dimensional sphere cap volume

From: John D'Errico

Date: 3 Feb, 2008 16:52:02

Message: 9 of 13

"Berlioz Berlioz" <speedo77@email.it> wrote in message
<fo4q0m$9go$1@fred.mathworks.com>...
> Many thanks I'am already working on this, but once u have
> the recurisve formula that it is pretty easy!.
>
> I think that the integral of (sint).^n can be easily
> computed using standard (quad, etc..) matlab integration
> instead of using the exact recursive formula.
> By the I'm working on a 20 dimensional space

Don't be at all surprised to find numerical
problems with quad in when you integrate
sin(t)^20. Of course, numerical problems may
still be a problem even with the recurrence.

John

Subject: n-dimensional sphere cap volume

From: Berlioz Berlioz

Date: 3 Feb, 2008 17:56:01

Message: 10 of 13

honestly, I never tried!
Anyway the recursive formuala leds to the sum of several sin
and cos so I think that this should not to be a problem....




"John D'Errico" <woodchips@rochester.rr.com> wrote in
message <fo4rfi$pjc$1@fred.mathworks.com>...
> "Berlioz Berlioz" <speedo77@email.it> wrote in message
> <fo4q0m$9go$1@fred.mathworks.com>...
> > Many thanks I'am already working on this, but once u have
> > the recurisve formula that it is pretty easy!.
> >
> > I think that the integral of (sint).^n can be easily
> > computed using standard (quad, etc..) matlab integration
> > instead of using the exact recursive formula.
> > By the I'm working on a 20 dimensional space
>
> Don't be at all surprised to find numerical
> problems with quad in when you integrate
> sin(t)^20. Of course, numerical problems may
> still be a problem even with the recurrence.
>
> John

Subject: n-dimensional sphere cap volume

From: Roger Stafford

Date: 3 Feb, 2008 20:09:01

Message: 11 of 13

"Berlioz Berlioz" <speedo77@email.it> wrote in message <fo4v7h$7i5
$1@fred.mathworks.com>...
> honestly, I never tried!
> Anyway the recursive formuala leds to the sum of several sin
> and cos so I think that this should not to be a problem....

  Yes, John had a good point. As n gets very large you will find that almost all
the volume of spherical "cross sections" will be concentrated in the near
vicinity of the sphere's "equator". It's as if the n-dimensional sphere has a
very fat belly. You can see this by plotting sin(t)^n for very large n and
noticing that the curve is almost zero everywhere except near t = pi/2 where
it has a large hump. Matlab's numerical quadrature functions don't do well
with such functions as this as a rule.

  You should be able to generate g = int('sin(t)^n','t',0,s) with a simple while-
loop something like this:

css = cos(s); sns = sin(s);
if mod(n,2)==0 % If n is even
 m = 0;
 g = s;
else % If n is odd
 m = 1;
 g = 1-css;
end
while m < n % Do the iteration from 0 or 1 upwards to n
 m = m+2;
 g =( (m-1)*g-sns^(m-1)*css)/m;
end

Again, as John warned, this may also give you accuracy problems for very
large n, because of the large number of repetitions and round-off errors in
the execution of the while-loop. However, I would tend to prefer this method
rather than numerical quadrature.

Roger Stafford

Subject: n-dimensional sphere cap volume

From: John D'Errico

Date: 3 Feb, 2008 21:59:01

Message: 12 of 13

"Berlioz Berlioz" <speedo77@email.it> wrote in message
<fo4v7h$7i5$1@fred.mathworks.com>...
> honestly, I never tried!
> Anyway the recursive formuala leds to the sum of several sin
> and cos so I think that this should not to be a problem....

I'm not saying not to try it. Only that this is
a thing to watch for. Knowing when to worry
is an important thing in numerical methods.

Think of it like this. sin(t) is always a number
between -1 and 1. However, sin(t)^n, where
n is large, is often very small. In only a very
small interval, will abs(sin(t)^n) be large. For
example,

ezplot(@x sin(x)^20)

As the exponent grows larger, this tends
more and more towards a series of delta
functions. Its a circumstance where quad
tends to have problems. In this case, its
probably not going to be a serious issue
(after having looked at the plot) until n
gets a bit larger than 20. The series solution
will still be much faster.

John

Subject: n-dimensional sphere cap volume

From: Berlioz Berlioz

Date: 3 Feb, 2008 22:01:02

Message: 13 of 13

I really thank you two for your suggestion!
I will try ur recursive approach and I will compare the
results with those obtained with quad

Just to try I used
f = @(x)(sin(x)).^20;
int = quad(f,0,pi);

getting int = 0.5535

many thanks
edo



"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
wrote in message <fo570t$a2b$1@fred.mathworks.com>...
> "Berlioz Berlioz" <speedo77@email.it> wrote in message
<fo4v7h$7i5
> $1@fred.mathworks.com>...
> > honestly, I never tried!
> > Anyway the recursive formuala leds to the sum of several sin
> > and cos so I think that this should not to be a problem....
>
> Yes, John had a good point. As n gets very large you
will find that almost all
> the volume of spherical "cross sections" will be
concentrated in the near
> vicinity of the sphere's "equator". It's as if the
n-dimensional sphere has a
> very fat belly. You can see this by plotting sin(t)^n for
very large n and
> noticing that the curve is almost zero everywhere except
near t = pi/2 where
> it has a large hump. Matlab's numerical quadrature
functions don't do well
> with such functions as this as a rule.
>
> You should be able to generate g =
int('sin(t)^n','t',0,s) with a simple while-
> loop something like this:
>
> css = cos(s); sns = sin(s);
> if mod(n,2)==0 % If n is even
> m = 0;
> g = s;
> else % If n is odd
> m = 1;
> g = 1-css;
> end
> while m < n % Do the iteration from 0 or 1 upwards to n
> m = m+2;
> g =( (m-1)*g-sns^(m-1)*css)/m;
> end
>
> Again, as John warned, this may also give you accuracy
problems for very
> large n, because of the large number of repetitions and
round-off errors in
> the execution of the while-loop. However, I would tend to
prefer this method
> rather than numerical quadrature.
>
> Roger Stafford
>

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
sphere Edoardo 2 Feb, 2008 19:54:57
cap Edoardo 2 Feb, 2008 19:54:57
dimensions Edoardo 2 Feb, 2008 19:54:57
volume Edoardo 2 Feb, 2008 19:54:57
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com