![]() |
|
|
#1 |
|
Banned
"Luigi"
Aug 2002
Team Italia
12CF16 Posts |
If the hypervolume of a hypercube is L4, what is the hypervolume of a hypersphere, and why?
Luigi |
|
|
|
|
|
#2 | |
|
Nov 2003
3×5×11 Posts |
Quote:
|
|
|
|
|
|
|
#3 | |
|
Banned
"Luigi"
Aug 2002
Team Italia
12CF16 Posts |
Quote:
Here is what I found in the meanwhile. Code:
module common
public :: initialize,integrate
integer, parameter, public :: double = 8
real (kind = double), parameter, public :: zero = 0.0
real (kind = double), public :: h, volume
integer, public :: d
contains
subroutine initialize()
print *, "dimension d?"
read *, d ! spatial dimension
print *, "integration interval h?"
read *, h
volume = 0.0
end subroutine initialize
recursive subroutine integrate(lower_r2, remaining_d)
! lower_r2 is contribution to r^2 from lower dimensions
real(kind = double),intent (in) :: lower_r2
integer, intent (in) :: remaining_d ! # dimensions to integrate
real (kind = double) :: x
x = 0.5*h ! mid-point approximation
if (remaining_d > 1) then
lower_d: do
call integrate(lower_r2 + x**2, remaining_d - 1)
x = x + h
if (x > 1) then
exit lower_d
end if
end do lower_d
else
last_d: do
if (x**2 + lower_r2 <= 1) then
volume = volume + h**(d - 1)*(1 - lower_r2 - x**2)**0.5
end if
x = x + h
if (x > 1) then
exit last_d
end if
end do last_d
end if
end subroutine integrate
end module common
program hypersphere
! programma originale di Jon Goldstein
use common
call initialize()
call integrate(zero, d - 1)
volume = (2**d)*volume
print *, volume
end program hypersphere
Thank you! There is more: Code:
Hyperspheres A hypersphere is the higher dimensional analogue of a 3-sphere. I won't explain this in any detail here, since the explanation is similar to that given for hypercubes. A 2-sphere is a circle. A 3-sphere is what we'd normally call a sphere. Strange things can happen in the higher dimensions. For example, consider the "volume" of a hypersphere. For simplicity, let's take a (hyper)sphere of radius 1 unit. The "volume" of a unit 2-sphere (i.e. area of a circle) is pi (about 3.1) square units. The volume of a unit 3-sphere is 4/3 pi (about 4.1) cubic units. A 4-sphere has volume of 4.9. A 5-sphere's volume is 5.2. Then something wierd happens; a 6-sphere has a volume of 5.1 units6. The volumes of hyperspheres with larger dimensions than this continue to decrease, so that an infinite dimensional unit hypersphere would have no hypervolume! The properties of things in higher dimensions are very interesting to consider. http://linneus20.ethz.ch:8080/1_5_3.html Especially last paragraph. Two peculiarities: We should use Gamma-function Knuth talked about it in vol. II, section 3.4.1.E(5), TAOCP. Luigi
|
|
|
|
|
|
|
#4 |
|
Banned
"Luigi"
Aug 2002
Team Italia
32·5·107 Posts |
Whops...
Nfortino thank you... your format is surely more easy and readable than what I found! Though if I read well, Vn(r) = Vnrn ==> r4(PI/4)2(1/2) = PI2r4/32 Though I trust your formula more than mine Luigi |
|
|
|
|
|
#5 | |
|
Banned
"Luigi"
Aug 2002
Team Italia
32·5·107 Posts |
Quote:
There is a typo in the link. After the sentence "The general formula is given by:", between the third and fourth passage. Congratulation Nfortino! Luigi |
|
|
|
|
|
|
#6 |
|
Sep 2002
29616 Posts |
I believe this is a correct translation into Pascal.
Code:
Program hypersphere;
var
zero : double;
h, volume : double;
d : longint;
Procedure initialize;
begin
write('dimension d ? ');
readln(d); // spatial dimension
write('integration interval h ? ');
readln(h);
volume := 0.0;
end;
Function power(num:double;exp:longint) : double;
var
r : double;
i : longint;
begin
if (exp = 0) then
r := 1.0
else
if (exp = 1) then
r := num
else
if (exp = 2) then
r := num*num
else begin
r := num;
for i := 2 to exp do
r := r * num;
end;
end;
Code:
Procedure integrate(lower_r2 : double; remaining_d : longint);
var
x : double;
begin
x := 0.5 * h; // mid-point approximation
if (remaining_d > 1) then begin
repeat
integrate(lower_r2 + x*x, remaining_d - 1);
x := x + h;
until (x > 1.0);
end
else begin
repeat
if ((x*x + lower_r2) <= 1) then
volume := volume + power(h,(d - 1)) * sqrt(1 - lower_r2 - x*x);
x := x + h;
until (x > 1.0);
end;
end;
begin // programma originale di Jon Goldstein
zero := 0.0;
initialize;
integrate(zero, d - 1);
volume := power(2.0,d)*volume;
writeln(volume:0:20);
end.
The original source appears to be Fortran90 or maybe Fortran95. Last fiddled with by dsouza123 on 2004-02-13 at 04:27 Reason: To correct the display of code. |
|
|
|
|
|
#7 | |
|
Banned
"Luigi"
Aug 2002
Team Italia
32×5×107 Posts |
Quote:
Pascal was my first-love programming language Luigi |
|
|
|
|
![]() |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How much will hyper threading help | primecrusader | Hardware | 7 | 2016-09-16 01:51 |
| Prime95 crash with Hyper-threading enabled | Laurent | Hardware | 4 | 2012-08-07 05:20 |
| Geometry Puzzle | davar55 | Puzzles | 33 | 2009-07-16 10:10 |
| Geometry | cherrycherry | Homework Help | 5 | 2007-08-31 00:34 |
| The Geometry of Time | mfgoode | Science & Technology | 4 | 2006-03-09 03:37 |