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

From LNTwww
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
  
{{quiz-Header|Buchseite=Stochastische Signaltheorie/Erzeugung von diskreten Zufallsgrößen
+
{{quiz-Header|Buchseite=Theory_of_Stochastic_Signals/Generation_of_Discrete_Random_Variables
 
}}
 
}}
  
[[File:P_ID123__Sto_Z_2_7.png|right|frame| C-Programm&nbsp; $z3$&nbsp; zur Generierung <br>einer Binomialverteilung]]
+
[[File:EN_Sto_Z_2_7.png|right|frame| C program&nbsp; $z3$&nbsp; for generating <br>a binomial distribution]]
Das nebenstehend angegebene C-Programm&nbsp; $z3$&nbsp; erzeugt sukzessive eine binomialverteilte Zufallsgr&ouml;&szlig;e mit den charakteristischen Kenngr&ouml;&szlig;en&nbsp; $I$&nbsp; und&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;  
*Es verwendet dabei das Programm&nbsp; $z1$, das bereits in&nbsp; [[Aufgaben:2.7_C-Programme_z1_und_z2|Aufgabe 2.7]]&nbsp; beschrieben und analysiert wurde.
+
*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;.
*Gehen Sie davon aus, dass das Programm mit den Parametern&nbsp; $I = 4$&nbsp; und&nbsp; $p = 0.75$&nbsp; aufgerufen wird.  
+
*Assume that the program is called with parameters&nbsp; $I = 4$&nbsp; and&nbsp; $p = 0.75$&nbsp;.  
*Die ersten acht vom Zufallsgenerator&nbsp; $\text{random()}$&nbsp; erzeugten reellwertigen Zahlen&nbsp; (alle zwischen Null und Eins)&nbsp; lauten:
+
*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 14: Line 14:
  
  
 
+
Hints:
 
+
*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]].
''Hinweise:''
 
*Die Aufgabe gehört zum  Kapitel&nbsp; [[Theory_of_Stochastic_Signals/Erzeugung_von_diskreten_Zufallsgrößen|Erzeugung von diskreten Zufallsgrößen]].
 
*Bezug genommen wird auch auf das Kapitel&nbsp; [[Theory_of_Stochastic_Signals/Binomialverteilung|Binomialverteilung]].
 
 
   
 
   
  
  
===Fragebogen===
+
===Questions===
  
 
<quiz display=simple>
 
<quiz display=simple>
{Welche der folgenden Aussagen sind zutreffend?
+
{Which of the following statements are true?
 
|type="[]"}
 
|type="[]"}
+ $z3$&nbsp; liefert eine binomialverteilte Zufallsgr&ouml;&szlig;e, weil mehrere Bin&auml;rwerte aufsummiert werden.
+
+ $z3$&nbsp; returns a binomially distributed random variable,&nbsp; because several binary values are summed up.
+ Zur Parameterübergabe  an das Programm $z1$ wird das Feld&nbsp; $\text{p_array} = \big [1-p, \ \ p \big]$&nbsp; benutzt.
+
+ To pass parameters to the program&nbsp; $z1$,&nbsp; the array &nbsp; $\text{p_array} = \big [1-p, \ \ p \big]$ &nbsp; is used.
+ Die &Uuml;bergabe von&nbsp; $M=2$&nbsp; muss mit "$\rm 2L$" geschehen, da&nbsp; $z1$&nbsp; einen Long-Wert erwartet.
+
+ Passing of&nbsp; $M=2$&nbsp; must be done with&nbsp; "$\rm 2L$",&nbsp; because&nbsp; $z1$&nbsp; expects a long (data type) value.
  
  
{Welcher Wert wird beim&nbsp; <u>ersten Aufruf</u>&nbsp; von&nbsp; $z3$&nbsp; ausgegeben?
+
{What value will be output on the&nbsp; <u>first call</u>&nbsp; of&nbsp; $z3$&nbsp;?
 
|type="{}"}
 
|type="{}"}
$z3 \ = \ $ { 2 }
+
$z3 \ = \ $ { 2 }
  
  
{Welcher Wert wird beim&nbsp; <u>zweiten Aufruf</u>&nbsp; von&nbsp; $z3$&nbsp; ausgegeben?
+
{What value will be output on the&nbsp; <u>second call</u>&nbsp; of&nbsp; $z3$&nbsp;?
 
|type="{}"}
 
|type="{}"}
 
$z3 \ = \ $ { 3 }
 
$z3 \ = \ $ { 3 }
Line 46: Line 43:
 
</quiz>
 
</quiz>
  
===Musterlösung===
+
===Solution===
 
{{ML-Kopf}}
 
{{ML-Kopf}}
'''(1)'''&nbsp; <u>Alle drei Aussagen</u> sind richtig.
+
'''(1)'''&nbsp; <u>All three statements</u>&nbsp; are true.
  
  
  
'''(2)'''&nbsp; Die reellwertigen Zufallszahlen&nbsp; $0.75$,&nbsp; $0.19$,&nbsp; $0.43$&nbsp; und&nbsp; $0.08$&nbsp; werden jeweils mit&nbsp; $0.25$&nbsp; verglichen.
+
'''(2)'''&nbsp; The real-valued random numbers&nbsp; $0.75$,&nbsp; $0.19$,&nbsp; $0.43$&nbsp; and&nbsp; $0.08$&nbsp; are each compared with&nbsp; $0.25$.
*Dieser Vergleich f&uuml;hrt zu den Bin&auml;rwerten&nbsp; $1, \ 0, \ 1, \ 0$.  
+
*This comparison results in the binary values&nbsp; $1, \ 0, \ 1, \ 0$.  
*Das ergibt im ersten Aufruf die Summe&nbsp; $\underline{z3 = 2}$.
+
*This results in the sum&nbsp; $\underline{z3 = 2}$&nbsp; for the first call.
  
  
  
'''(3)'''&nbsp; Analog zum Ergebnis der Teilaufgabe&nbsp; '''(2)'''&nbsp; treten nun wegen der Zufallswerte&nbsp; $0.99$,&nbsp; $0.32$,&nbsp; $0.53$&nbsp; und&nbsp; $0.02$&nbsp; die Bin&auml;rwerte&nbsp; $1, \ 1, \ 1, \ 0$&nbsp; auf.  
+
'''(3)'''&nbsp; Analogous to the result of the subtask&nbsp; '''(2)'''&nbsp; the binary values&nbsp; $1, \ 1, \ 1, \ 0$&nbsp; now occur because of the random values&nbsp; $0.99$,&nbsp; $0.32$,&nbsp; $0.53$&nbsp; and&nbsp; $0.02$&nbsp; .  
*Dies f&uuml;hrt zum Ausgabewert&nbsp; $\underline{z3 = 3}$&nbsp; (wiederum Summe der Binärwerte).
+
*This leads to the output value&nbsp; $\underline{z3 = 3}$&nbsp; (again the sum of binary values).
 
{{ML-Fuß}}
 
{{ML-Fuß}}
  

Latest revision as of 14:58, 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}$  for 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 the sum of binary values).