Riemann sum multiple dimensions

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

Jan
Jan 2017년 5월 8일
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 2017년 5월 8일
Ok, thank you for your answer. I will try to make my code somewhat more readable.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2017년 5월 8일

1 개 추천

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.

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

질문:

Ema
2017년 5월 8일

편집:

Ema
2017년 5월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by