n=1e6;%stevilo nakljucnih poskusov // number of generated random numbers a=2;%polosi elipsoida // half-axi of the elispoid b=3; c=4; Ve=4*pi*a*b*c/3%dejanski volumen elipsoida // actual volume of the elipsiob X=2*a*rand(1,n)-a;%izrebamo n enkomerno porazdeljenih nakljucnih // generating n uniform random numbers Y=2*b*rand(1,n)-b;%stevil med -2a in 2a, -2b in 2b in -2c in 2c // between -2a and 2a, -2b and 2b and -2c and 2c Z=2*c*rand(1,n)-c; Vk=8*a*b*c;%volumen kvadra, kamor lahko padejo nakljucno izrebane tocke // volume of the region where we can get the %random points m=sum(X.^2/a^2+Y.^2/b^2+Z.^2/c^2<1);%prestejemo koliko tock pade znotraj elipsoida // we count the number %of points that land in the elipsoid ocena=Vk*m/n%ocena za volumen elipsoida // the estimate for the volume of the elipsoid razlika= Ve-ocena% razlika med dejansko vrednostjo in oceno // difference between the exact value and estimate