Riemann sum multiple dimensions
2 次查看(过去 30 天)
显示 更早的评论
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
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.
回答(1 个)
Jan
2017-5-8
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Mathematics and Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!