Difference between revisions of "Aufgaben:Exercise 2.7Z: C Program "z3""

From LNTwww
Line 4: Line 4:
  
 
[[File:EN_Sto_Z_2_7.png|right|frame| C program&nbsp; $z3$&nbsp; for generating <br>a binomial distribution]]
 
[[File:EN_Sto_Z_2_7.png|right|frame| C program&nbsp; $z3$&nbsp; for generating <br>a binomial distribution]]
The C program&nbsp; $z3$&nbsp; given opposite successively generates a binomially distributed random variable with the characteristic variables&nbsp; $I$&nbsp; and&nbsp; $p$.&nbsp;  
+
The C program&nbsp; $z3$&nbsp; given here successively generates a binomially distributed random variable with the characteristic variables&nbsp; $I$&nbsp; and&nbsp; $p$.&nbsp;  
 
*It uses the program&nbsp; $z1$ already described and analyzed in&nbsp; [[Aufgaben:Exercise_2.7:_C_Programs_"z1"_and_"z2"|Exercise 2.7]]&nbsp;.
 
*It uses the program&nbsp; $z1$ already described and analyzed in&nbsp; [[Aufgaben:Exercise_2.7:_C_Programs_"z1"_and_"z2"|Exercise 2.7]]&nbsp;.
 
*Assume that the program is called with parameters&nbsp; $I = 4$&nbsp; and&nbsp; $p = 0.75$&nbsp;.  
 
*Assume that the program is called with parameters&nbsp; $I = 4$&nbsp; and&nbsp; $p = 0.75$&nbsp;.  
 
*The first eight real-valued numbers&nbsp; (all between zero and one)&nbsp; generated by the random generator&nbsp; $\text{random()}$&nbsp; are:
 
*The first eight real-valued numbers&nbsp; (all between zero and one)&nbsp; generated by the random generator&nbsp; $\text{random()}$&nbsp; are:
 
:$$\rm 0.75, \ 0.19, \ 0.43, \ 0.08, \ 0.99, \ 0.32, \ 0.53, \ 0.02.$$
 
:$$\rm 0.75, \ 0.19, \ 0.43, \ 0.08, \ 0.99, \ 0.32, \ 0.53, \ 0.02.$$
 
 
 
 
  
  
Line 20: Line 16:
 
Hints:
 
Hints:
 
*The exercise belongs to the chapter&nbsp; [[Theory_of_Stochastic_Signals/Generation_of_Discrete_Random_Variables|Generation of Discrete Random Variables]].
 
*The exercise belongs to the chapter&nbsp; [[Theory_of_Stochastic_Signals/Generation_of_Discrete_Random_Variables|Generation of Discrete Random Variables]].
*Reference is also made to the chapter&nbsp; [[Theory_of_Stochastic_Signals/Binomial_Distribution|binomial distribution]].
+
*Reference is also made to the chapter&nbsp; [[Theory_of_Stochastic_Signals/Binomial_Distribution|Binomial distribution]].
 
   
 
   
  
Line 29: Line 25:
 
{Which of the following statements are true?
 
{Which of the following statements are true?
 
|type="[]"}
 
|type="[]"}
+ $z3$&nbsp; returns a binomially distributed random variable, because several binary values are summed up.
+
+ $z3$&nbsp; returns a binomially distributed random variable,&nbsp; because several binary values are summed up.
+ To pass parameters to the program $z1$, the array&nbsp; $\text{p_array} = \big [1-p, \ \ p \big]$&nbsp; is used.
+
+ To pass parameters to the program&nbsp; $z1$,&nbsp; the array &nbsp; $\text{p_array} = \big [1-p, \ \ p \big]$ &nbsp; is used.
+ Passing of&nbsp; $M=2$&nbsp; must be done with "$\rm 2L$", because&nbsp; $z1$&nbsp; expects a long (data type) value.
+
+ Passing of&nbsp; $M=2$&nbsp; must be done with&nbsp; "$\rm 2L$",&nbsp; because&nbsp; $z1$&nbsp; expects a long (data type) value.
  
  
{What value will be output on&nbsp; <u>first call</u>&nbsp; of&nbsp; $z3$&nbsp;?
+
{What value will be output on the&nbsp; <u>first call</u>&nbsp; of&nbsp; $z3$&nbsp;?
 
|type="{}"}
 
|type="{}"}
 
$z3 \ = \ $ { 2 }
 
$z3 \ = \ $ { 2 }
  
  
{What value will be output on&nbsp; <u>second call</u>&nbsp; of&nbsp; $z3$&nbsp;?
+
{What value will be output on the&nbsp; <u>second call</u>&nbsp; of&nbsp; $z3$&nbsp;?
 
|type="{}"}
 
|type="{}"}
 
$z3 \ = \ $ { 3 }
 
$z3 \ = \ $ { 3 }

Revision as of 14:55, 29 December 2021

C program  $z3$  for generating
a binomial distribution

The C program  $z3$  given here successively generates a binomially distributed random variable with the characteristic variables  $I$  and  $p$. 

  • It uses the program  $z1$ already described and analyzed in  Exercise 2.7 .
  • Assume that the program is called with parameters  $I = 4$  and  $p = 0.75$ .
  • The first eight real-valued numbers  (all between zero and one)  generated by the random generator  $\text{random()}$  are:
$$\rm 0.75, \ 0.19, \ 0.43, \ 0.08, \ 0.99, \ 0.32, \ 0.53, \ 0.02.$$



Hints:


Questions

1

Which of the following statements are true?

$z3$  returns a binomially distributed random variable,  because several binary values are summed up.
To pass parameters to the program  $z1$,  the array   $\text{p_array} = \big [1-p, \ \ p \big]$   is used.
Passing of  $M=2$  must be done with  "$\rm 2L$",  because  $z1$  expects a long (data type) value.

2

What value will be output on the  first call  of  $z3$ ?

$z3 \ = \ $

3

What value will be output on the  second call  of  $z3$ ?

$z3 \ = \ $


Solution

(1)  All three statements are true.


(2)  The real-valued random numbers  $0.75$,  $0.19$,  $0.43$  and  $0.08$  are each compared with  $0.25$  .

  • This comparison results in the binary values  $1, \ 0, \ 1, \ 0$.
  • This results in the sum  $\underline{z3 = 2}$ in the first call.


(3)  Analogous to the result of the subtask  (2)  the binary values  $1, \ 1, \ 1, \ 0$  now occur because of the random values  $0.99$,  $0.32$,  $0.53$  and  $0.02$  .

  • This leads to the output value  $\underline{z3 = 3}$  (again sum of binary values).