Can anyone help me out what does sign(rand-0.5) command mean

26 ビュー (過去 30 日間)
Mashrur Zawad
Mashrur Zawad 2022 年 3 月 19 日
コメント済み: Atsushi Ueno 2022 年 3 月 19 日
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)

採用された回答

Star Strider
Star Strider 2022 年 3 月 19 日
The ‘sign(rand-0.5)’ returns the sign (-1,0,1) of that result —
for k = 1:10
r = rand
X = sign(r-0.5)
end
r = 0.1812
X = -1
r = 0.5620
X = 1
r = 0.3196
X = -1
r = 0.6013
X = 1
r = 0.7162
X = 1
r = 0.7427
X = 1
r = 0.9730
X = 1
r = 0.6988
X = 1
r = 0.4561
X = -1
r = 0.5195
X = 1
.
  2 件のコメント
Mashrur Zawad
Mashrur Zawad 2022 年 3 月 19 日
Thanks got it.What about rand-0.5?What -0.5 signifies?Does it denote the maximum and minimum range of random numbers?
Torsten
Torsten 2022 年 3 月 19 日
編集済み: Torsten 2022 年 3 月 19 日
You take a random number between 0 and 1 (that's what rand does).
Then you subtract 0.5 from this random number.
The result will be between -0.5 and 0.5 ( 0 - 0.5 and 1 - 0.5 are the extremes that can happen) with equal probability.
So the probability of getting a result > 0 (namely a result between 0 and 0.5) is equal to the probability of getting a result < 0 (namely between -0.5 and 0).
Can you now answer the question what the probability of getting a result > 0 is ?

サインインしてコメントする。

その他の回答 (1 件)

Atsushi Ueno
Atsushi Ueno 2022 年 3 月 19 日
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 件のコメント
Mashrur Zawad
Mashrur Zawad 2022 年 3 月 19 日
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)
Can you tell me how to solve this?
Atsushi Ueno
Atsushi Ueno 2022 年 3 月 19 日
  1. 50%
  2. 50%
  3. 50%
Do you mean you want exact probability?
I mean you need probability of sign(rand-0.5)==0 or not.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by