I am using a Matlab built-in function rand
in an algorithm to generate non-zero elements. It is explained that the function rand
should produce a real number in the open interval (0,1). However, when I run the code, I get zero in most of the elements. Let me explain the code: there is a for
loop. In each iteration, I am trying to multiply a random number with a certain variable that is subtracted by the multiplication of the same variable with another random number from the previous iteration. So by math, the variable approaches to zero, but it cannot be zero. Can you give me a suggestion about why it is happening? If convenient, can you recommend a way to avoid this?
For your information, I put the algorithm below. The variable which will decay at each iteration is Volume. The desired output is collected at the variable frag.
for i=1:1:numbofprogeny
frag(i,1)=Volume*rand;
Volume=Volume-frag;
end
Aucun commentaire:
Enregistrer un commentaire