# Thread: The volume of the interior of an ellipsoid in Rn deminsion, help would be appreciated

1. ## The volume of the interior of an ellipsoid in Rn deminsion, help would be appreciated

hi everyone
i have been given this problem to solve, usage of R or Rstudio is required so solve it.
i would appreciate undescriply for anyone helping me solve it, even if it costs me money.
the problem is attached to this thread, please take a moment to check it
thanks again

2. ## Re: The volume of the interior of an ellipsoid in Rn deminsion, help would be appreci

What did you find out so far?
Do you know how stochastic integration works?
Where do you struggle?

As the program for the integration can be quite simple, I do not think that the platform is important here.

3. ## Re: The volume of the interior of an ellipsoid in Rn deminsion, help would be appreci

hey, thanks for your time to check it out.. yes i have so far found the 2D of how the ellipsoid should be enclosed at. but that is supposed to be
the easiest part. here is the Rcode. which u can put and check it out..if u can help with 3D..damn ur the king..

nsim = 10000
dim = 2
a = c(1,1) # a cricle actually
X = matrix(nr=nsim,nc=dim,data=runif(nsim*dim,min=-1,max=1))

## checking if a point is inside
A = (X^2 %*% (1/a^2)) # contains the (x[1]/ a[1])^2 and (x[2]/a[2])^2 values
B = apply(X=A,MARGIN=1,FUN=sum) # sum entries on each line

inside = ( B < 1) # check if each points is inside

plot(X,col=1+inside)

Vhat = mean(inside)*4
Vhat

4. ## Re: The volume of the interior of an ellipsoid in Rn deminsion, help would be appreci

I do not know what c(1,1) does, but is there something like c(1,1,1) for 3 dimensions? Is there an n-dimensional version of that?
The basic idea is to generate n random numbers each, (scale, ) square and add them.
"Vhat = mean(inside)*4" -> in general, the factor is 2^dim.

5. ## Re: The volume of the interior of an ellipsoid in Rn deminsion, help would be appreci

yes the idea is n-deminsional. could u make something out of it?

6. ## Re: The volume of the interior of an ellipsoid in Rn deminsion, help would be appreci

R might have a different way to do this, but in C++ my approach would look like this:

Code:
int dimensions=10;
int inside=0;
int npoints=100000;

double sqsum;
double rnd;
for(int k=0;k<npoints;k++) {
sqsum=0;
for(int i=0;i<dimensions;i++) {
rnd=rand()/RAND_MAX;
sqsum+=rnd*rnd;
}
if(sqsum<1) {
inside++;
}
double volume=inside/npoints*2**dimensions;
cout<<"The volume is approximately "<<volume<<endl;
I did not include scaling for ellipsoids here.