Can anyone help me out what does sign(rand-0.5) command mean
Show older comments
1.Probability of X >0 if X= rand-0.5 2.Probability of X =1 if X= sign(rand-0.5) 3.Probability of X =-1 if X= sign(rand-0.5)
Accepted Answer
More Answers (1)
Atsushi Ueno
on 19 Mar 2022
1 vote
rand generates a uniformly distributed random number between 0 and 1.
So, rand-0.5 means random number between -0.5 and 0.5.
rand returns an array Y the same size as x, where each element of Y is:
- 1 if the corresponding element of x is greater than 0.
- 0 if the corresponding element of x equals 0.
- -1 if the corresponding element of x is less than 0.
So, sign(rand-0.5) usually outputs -1 or 1 like a result of coin toss.
It is extremely rare for sign(rand-0.5) to output 0
2 Comments
Mashrur Zawad
on 19 Mar 2022
Atsushi Ueno
on 19 Mar 2022
- 50%
- 50%
- 50%
Do you mean you want exact probability?
I mean you need probability of sign(rand-0.5)==0 or not.
Categories
Find more on Random Number Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!