volumeofsphere matlab function need help
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre Lighting, Transparency, and Shading en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!