volumeofsphere matlab function need help
1 回表示 (過去 30 日間)
古いコメントを表示
I put 10^4 into the function and I should be expecting Number of points inside sphere to be 3 and the area should be 0.0024. Am I missing something if so what do I need to change ?
function volumeofsphere3(n)
ds = RandStream.getGlobalStream;
reset(ds);
x=2*rand(n,1);
y=rand(n,1);
z=rand(n,1);
count=0
for i=1:n
r=sqrt((x(i)-1/3)^2+(y(i)-1/3)^2+(z(i)-1/2)^2);
if r<=0.04
count=count+1;
end
end
fprintf(1,'Number of points inside sphere: %d\n', count)
Area_of_Sphere=8*(count/n)
end
0 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Lighting, Transparency, and Shading についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!