I am trying to solve a problem in which when a particle is launched it has 3 possibilities: 1 - It is absorbed by the plate 2 - It bounces 3 - It crosses
The formulas of the movement of the particle are made by using a random number (rand()) the case is that I have to enumerate the times that this happens with 1000 particles, although when putting it in a loop, it does not generate a number 1000 times different, that is to say 1 for each iteration but it generates one and uses it for the "1000 launches" so the counter results are either 1000 in one or 1000 in another or a random number between 150 and 250 from what I have seen (another thing I really don't understand)
How could I go about solving this?
Thank you very much in advance and I leave the code here.
By using "rand" outside the loop it is only being executed once.
First create the 1000 random numbers and apply them later in your for loop
You can pass arguments to the "rand" function in various ways, for example
rand(n) - returns an array of random numbers of dimensions nxn
In your case, you can use the command X = rand(10,10) to generate an array of dimensions 10x10
Your variable X contains this array. Here you can do a sweep with two nested fors or do an elementwise multiply/divide using a dot before the operator
Namely:
C = A.*B
Recommendation: In matlab in the command window you can type
help
+ "the function with which you have doubt", which will open a window with information relevant to that function.