How do I get random variables generated from a distribution in [-1, 1]?
2 vues (au cours des 30 derniers jours)
Hi Everyone, I have h represent the direct problem for the matrix (2N,1) , N=30,
I tried to get noise. It is required to multiply h by (1+0.01*\epsilon), where \epsilon is a random variables generated from a distribution in [-1, 1]. So I write the noise as
but i think there is something wrong, i attached the figure that represnt h with noise and without noise.
Plus de réponses (1)
John D'Errico le 28 Mai 2023
The MATLAB crystal ball is foggy today. You give us a tiny fragment of code, and then tell us that something strange happens. PROBABLE USER ERROR.
This fragment generates random numbers on the interval [-1,1].
But this fragment generates random numbers on a different interval:
What is that interval? Think about what multiplying a uniform random number does. Think about what adding a constant to that uniform number does.
For example, RAND generates numbers randomly and uniformly in the interval (0,1). Then think about what a*RAND does? It will now be uniform and random on the interval (0,a). Do you understand that?
Similarly, what does adding a constant do to rand? That is, a+rand will be uniform on the interval (a,1+a). Now look carefully at those expressions. Start with the first.
This maps rand first into the interval (0,2), then by subtracting 1, the result will be uniform on the interval (-1,1).
Now look at what you have. You multiply by 0.1, which maps that (-1,1) interval into (-0.01,0.01). Then you add 1. So now the random numbers are mapped into (0.99,1.01). Finally, you multiply by h. So the second code fragment generates uniform random numbers on the interval (0.99*h,1.01*h).
As for what you did wrong with those numbers, that is between you and your computer, since you have refrained from telling us anything at all.