Docsity

4 Solved Exercises on Simulation Method in Statistics Program | CSCI 426, Study notes of Computer Science

Toggle sidebar
bg1
CSci 426/526 — Simulation — Fall 2004
Examples
To help you get a sense of my expectations, enclosed are (partial) solutions to three typical
exercises. These three exercises illustrate the range of “solution types” you will be expected
to produce.
•exercise 1.2.2: This is a multi-part exercise that requires a modify-an-existing-
program, do-some-computing, and explain-what-you-did solution. Note the explicit
reference to relevant material in the text. As an alternative to the in-line format used
to discuss how program ssq1 was modified, you could provide a printed copy of the
(complete) modified program with a highlighting marker used to clearly identify the
modifications.
•exercise 1.2.4: This is a prove/demonstrate/show mathematical exercise that requires
(of course) a mathematical solution.
•exercise 2.1.1: This is a multi-part exercise that requires a little bit of math and a
build-from-scratch program with corresponding numerical results. Note that a printed
copy of the program is included as part of the solution. Note also the explicit reference
to relevant material in the text.
You will note that all the solutions are typeset. I happen to use L
A
T
EX for technical typeset-
ting; some prefer to use plain T
EX. You can use either, or neither, or you can use any other
document preparation system you are familiar with — provided it can do a decent job with
technical typesetting. If you prefer, you can write your solutions (neatly) by hand. I care
much more about the content than the style.
pf3
pf4
pf5

Partial preview of the text

Download 4 Solved Exercises on Simulation Method in Statistics Program | CSCI 426 and more Study notes Computer Science in PDF only on Docsity!

CSci 426/526 — Simulation — Fall 2004

Examples

To help you get a sense of my expectations, enclosed are (partial) solutions to three typical exercises. These three exercises illustrate the range of “solution types” you will be expected to produce.

  • exercise 1.2.2: This is a multi-part exercise that requires a modify-an-existing- program, do-some-computing, and explain-what-you-did solution. Note the explicit reference to relevant material in the text. As an alternative to the in-line format used to discuss how program ssq1 was modified, you could provide a printed copy of the (complete) modified program with a highlighting marker used to clearly identify the modifications.
  • exercise 1.2.4: This is a prove/demonstrate/show mathematical exercise that requires (of course) a mathematical solution.
  • exercise 2.1.1: This is a multi-part exercise that requires a little bit of math and a build-from-scratch program with corresponding numerical results. Note that a printed copy of the program is included as part of the solution. Note also the explicit reference to relevant material in the text.

You will note that all the solutions are typeset. I happen to use LATEX for technical typeset- ting; some prefer to use plain TEX. You can use either, or neither, or you can use any other document preparation system you are familiar with — provided it can do a decent job with technical typesetting. If you prefer, you can write your solutions (neatly) by hand. I care much more about the content than the style.

Exercise 1.2.

(a) Modify program ssq1 to output the additional statistics ¯l, ¯q and ¯x. (b) Similar to example 1.2.8, use this program to compute a table of ¯l, ¯q and ¯x for traffic intensities of 0 .6, 0.7, 0.8, 0.9, 1.0, 1.1, and 1.2. (c) Comment on how ¯l, ¯q and ¯x depend on the traffic intensity. (d) Relative to examples 1.2.8 and 1.2.9, if it is decided that ¯q greater than 5 .0 is not acceptable, to d.dd precision what systematic increase in service times would be acceptable?

(a) The modification is based on the equations in theorem 1.2.1 or, equivalently, Little’s equations (see page 1.2.9). In particular, relative to these equations, when program ssq terminates there will be the following correspondence between mathematical quantities and program variables

c ∑n ←→ departure n ∑i=1^ wi^ ←→^ sum.wait n ∑in=1^ di^ ←→^ sum.delay i=1 si^ ←→^ sum.service.

Because ¯l =

( (^) n

cn

) w ¯ =

cn

∑n

i=

wi

with analogous equations for ¯q and ¯x, it follows that the only modification that must be made to program ssq1 to output ¯l, ¯q and ¯x is the addition of the following three printf statements

printf("average nbr in the node .... = ", sum.wait / departure); printf("average nbr in the queue ... = ", sum.delay / departure); printf("utilization ................ = ", sum.service / departure);

(b) Using the data in the file ssq1.dat produces a traffic intensity of ¯s/r¯ ' 0 .721. To change the traffic intensity to a specific value, say ρ, we can multiply each service time by ρ/ 0 .721. At the expense of needing to re-compile each time ρ is changed, the easiest way to accomplish this modification to program ssq1 is to add the line

  • #define FACTOR (0.7 / 0.721) to the beginning of the program (for ρ = 0.7), and modify the function GetService by changing the return to
  • return(FACTOR * s);

Exercise 1.2.

Complete the proof of theorem 1.2.1.

The solution to this exercise is based on the proof/derivation of the “wait” equation on page 1.2.9, modified to handle the “delay” and “service” equations.

To derive the delay equation, for each job i = 1, 2 ,... , n define a delay indicator function θi(t) that is 1 when the ith^ job is in the queue and is 0 otherwise

θi(t) =

{ 1 ai < t < bi 0 otherwise.

Then the number in the queue at time t is

q(t) =

∑^ n

i=

θi(t) 0 < t < cn

and so (^) ∫ cn 0

q(t) dt =

∫ (^) cn

0

∑^ n

i=

θi(t) dt =

∑^ n

i=

∫ (^) cn

0

θi(t) dt =

∑^ n

i=

(bi − ai) =

∑^ n

i=

di.

The service equation can be derived in a similar way. Or, as an alternative, note that l(t) = q(t) + x(t) for 0 < t < cn and wi = di + si for 1 = 1, 2 ,... , n so that we can use the wait and delay equations to derive the service equation, as illustrated ∫ (^) cn

0

x(t) dt

∫ (^) cn

0

x(t) dt =

∫ (^) cn

0

(l(t) − q(t)) dt

=

∫ (^) cn

0

l(t) dt −

∫ (^) cn

0

q(t) dt

=

∑^ n

i=

wi −

∑^ n

i=

di

∑^ n

i=

(wi − di)

∑^ n

i=

si.

Exercise 2.1.

For the tiny Lehmer generator defined by g(x) = ax mod 127, find all the full-period mul- tipliers. (a) How many are there? (b) What is the smallest one? (a) Because the prime factorization of m − 1 = 126 is 2 · 32 · 7 and because

(2 − 1)(3 − 1)(7 − 1) 2 · 3 · 7

from theorem 2.1.3 we know that there are 36 full-period multipliers.

(b) Provided the program parameter A is a full-period multiplier, the enclosed program, based on algorithms 2.1.1 and 2.1.2, generates and prints (“finds”) all of the 36 full-period multipliers. (If A is not a full-period multipler the program will produce no output.) By inspection of the output we see that 3 is the smallest full-period multiplier.

  • exercise 2.1.
  • the output is ...
  • 3 116 109 92 86 12 83 112 55 114 48 78
  • 67 93 106 65 58 14 118 46 43 6 56 91
  • 57 45 39 97 110 101 53 96 29 7 23 85

*/

#include <stdio.h>

#define M 127 /* for this modulus ... / #define A 3 / 3 is a full-period multiplier */

long g(long x) { return ((A * x) % M); }

long gcd(long a, long b) /* from appendix B, use a > 0 and b > 0 */ { long r = a % b; while (r > 0) { a = b; b = r; r = a % b;