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

From LNTwww
(Die Seite wurde neu angelegt: „ {{quiz-Header|Buchseite=Stochastische Signaltheorie/Erzeugung von diskreten Zufallsgrößen }} right| :Das nebenstehend ange…“)
 
 
(21 intermediate revisions by 5 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|]]
+
[[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  <i>z</i>3 erzeugt sukzessive eine binomialverteilte Zufallsgr&ouml;&szlig;e mit den charakteristischen Kenngr&ouml;&szlig;en <i>I</i> und <i>p</i>. Es verwendet dabei das Programm <i>z</i>1, das bereits in Aufgabe A2.7 beschrieben und analysiert wurde.
+
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;.
 +
*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:
 +
:$$\rm 0.75, \ 0.19, \ 0.43, \ 0.08, \ 0.99, \ 0.32, \ 0.53, \ 0.02.$$
  
:Gehen Sie davon aus, dass das Programm mit den Parametern <i>I</i> = 4 und <i>p</i> = 0.75 aufgerufen wird. Die ersten acht vom Zufallsgenerator <i>random</i>() erzeugten reellwertigen Zahlen (alle zwischen 0 und 1) lauten:
 
:$$\rm 0.75, 0.19, 0.43, 0.08, 0.99, 0.32, 0.53, 0.02.$$
 
  
:<br><br><br><br><br><br><br>
 
<b>Hinweis</b>: Diese Aufgabe gehört zu Kapitel 2.5.
 
  
===Fragebogen===
+
 
 +
 
 +
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]].
 +
 +
 
 +
 
 +
===Questions===
  
 
<quiz display=simple>
 
<quiz display=simple>
{Welche der nachfolgenden Aussagen sind zutreffend?
+
{Which of the following statements are true?
 
|type="[]"}
 
|type="[]"}
+ Das Programm <i>z</i>3 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 &Uuml;bergabe der Wahrscheinlichkeiten an das Programm <i>z</i>1 wird das Feld <i>p_array</i> = [1&ndash;<i>p</i>, <i>p</i>] 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 &bdquo;<i>M</i> = 2&rdquo; an die Funktion <i>z</i>1 muss mit &bdquo;2L&rdquo; geschehen, da dieses Programm 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 ersten Aufruf von <i>z</i>3 ausgegeben?
+
{What value will be output on the&nbsp; <u>first call</u>&nbsp; of&nbsp; $z3$&nbsp;?
 
|type="{}"}
 
|type="{}"}
$1.\ Aufruf:\ \ \ \ z3$ = { 2 3% }
+
$z3 \ = \ $ { 2 }
  
  
{Welcher Wert wird beim zweiten Aufruf von <i>z</i>3 ausgegeben?
+
{What value will be output on the&nbsp; <u>second call</u>&nbsp; of&nbsp; $z3$&nbsp;?
 
|type="{}"}
 
|type="{}"}
$2.\ Aufruf:\ \ \ \ z3$ = { 3 3% }
+
$z3 \ = \ $ { 3 }
  
  
Line 35: Line 43:
 
</quiz>
 
</quiz>
  
===Musterlösung===
+
===Solution===
 
{{ML-Kopf}}
 
{{ML-Kopf}}
:<b>1.</b>&nbsp;&nbsp;<u>Alle drei</u> Aussagen sind richtig.
+
'''(1)'''&nbsp; <u>All three statements</u>&nbsp; are true.
 +
 
 +
 
 +
 
 +
'''(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$.
 +
*This comparison results in the binary values&nbsp; $1, \ 0, \ 1, \ 0$.
 +
*This results in the sum&nbsp; $\underline{z3 = 2}$&nbsp; for the first call.
 +
 
  
:<b>2.</b>&nbsp;&nbsp;Die reellwertigen Zufallszahlen 0.75, 0.19, 0.43 und 0.08 werden jeweils mit 0.25 verglichen und f&uuml;hren zu den Bin&auml;rwerten 1, 0, 1, 0. Das ergibt im ersten Aufruf die Summe <u><i>z</i>3 = 2</u>.
 
  
:<b>3.</b>&nbsp;&nbsp;Analog zum Ergebnis von b) treten wegen der Zufallswerte 0.99, 0.32, 0.53 und 0.02 nun die Bin&auml;rwerte 1, 1, 1 und 0 auf. Dies f&uuml;hrt zum Ausgabewert <u><i>z</i>3 = 3</u> (Summe der Binärwerte).
+
'''(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; .  
 +
*This leads to the output value&nbsp; $\underline{z3 = 3}$&nbsp; (again the sum of binary values).
 
{{ML-Fuß}}
 
{{ML-Fuß}}
  
  
  
[[Category:Aufgaben zu Stochastische Signaltheorie|^2.5 Erzeugung von diskreten Zufallsgrößen^]]
+
[[Category:Theory of Stochastic Signals: Exercises|^2.5 Generation of Discrete Random Variables^]]

Latest revision as of 15: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).