Azzera filtri
Azzera filtri

volumeofsphere matlab function need help

1 visualizzazione (ultimi 30 giorni)
gracias claude
gracias claude il 11 Apr 2021
Modificato: dpb il 11 Apr 2021
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

Risposte (0)

Categorie

Scopri di più su Lighting, Transparency, and Shading in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by