Riemann sum multiple dimensions

2 vues (au cours des 30 derniers jours)
Ema
Ema le 8 Mai 2017
Modifié(e) : Ema le 8 Mai 2017
I have 2 tasks. a) Try to approximate the volume of a sphere with radius 1. Do this with riemann sum in matlab. What ive done in my code is to change from x,y,z to spheric coordinates with r,theta and phi. my code is :
r_max=1;
theta_max=pi;
phi_max=2*pi
nof_r=100;
nof_theta=100;
nof_phi=100;
dr=r_max/nof_r;
dtheta=theta_max/nof_theta;
dphi=phi_max/nof_phi;
I=0;
for i=1:nof_r
for j=1:nof_theta
for k=1:nof_phi
r=(i-1/2)*dr;
theta=(j-1/2)*dtheta;
phi=(k-1/2)*dphi
I=I+r^2*sin(theta)*dr*dtheta*dphi;
end % k
end % j
end % i
I think i got this one.
But in the second part. I have to approximate the volume of a sphere in 10 dimension were the real answer is pi^5/120. (radius 1) In the first part i did used spheric coordinates. Maybe i should have done this with something else? Because i have no idea how to express it with the same method in a 10th dimension.
  2 commentaires
Jan
Jan le 8 Mai 2017
Due to the lack of comments it is hard to guess the intention of the code. Stuffing multiple command in a line decreases the readability also. Remember that most of the members of the forum do not work with Riemann sums currently, in opposite to you.
Ema
Ema le 8 Mai 2017
Ok, thank you for your answer. I will try to make my code somewhat more readable.

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 8 Mai 2017
The question does not concern the implementation in Matlab, but the mathematical problem. See https://en.wikipedia.org/wiki/N-sphere for the definition of the volume elements of an N-sphere.

Catégories

En savoir plus sur Mathematics and Optimization dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by