solution01 - while that for = 128 should oscillate around....

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Solutions to Homework 01 1. One possible program: #include <stdio.h> #include <stdlib.h> #include <math.h> main(int argc, char **argv) { int i, alpha, old, new; if (argc != 3) { printf("Too few arguments \n"); printf("Usage: %s <alpha> <X_0> ", argv[0]); exit(1); } alpha = atoi(argv[2]); old = atoi(argv[3]); for (i=0; i<1000; i++) { new = (alpha*old)%8191; printf("%d \n", new); old = new; } } The main thing to worry about is the line new = (alpha*old)%8191 . Also note that the pseudo random nubers that are generated may not have all the numbers between 0-8191. Also there should be sequence of length around 13 which keeps repeating, for α = 128. The exact sequence depends on the value of α and X (0). 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2. <X> n = 1 n n X j =1 X ( j ) = 1 n X ( n )+ n - 1 X j =1 X ( j ) = 1 n X ( n )+( n - 1) 1 n - 1 n - 1 X j =1 X ( j ) = 1 n { X ( n )+( n - 1) <X> n - 1 } = <X> n - 1 + X ( n ) - <X> n - 1 n 3. The students can take the sequence they generate and put it in any plotting software they like. The Fnal value of the average for α = 126 should converge to around 4096
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: while that for = 128 should oscillate around. Note that the oscillation for the case of = 128 repeat every 13 values around a value close to 1260. The general shape of the plots is given in igure 1. 2 1000 2000 3000 4000 5000 6000 7000 8000 100 200 300 400 500 600 700 800 900 1000 &quot;ave128&quot; 1000 2000 3000 4000 5000 6000 7000 8000 100 200 300 400 500 600 700 800 900 1000 &quot;ave126&quot; (a) = 128 (b) = 126 1100 1150 1200 1250 1300 1350 1400 1450 1500 100 200 300 400 500 600 700 800 900 1000 &quot;ave128&quot; 3000 3500 4000 4500 5000 100 200 300 400 500 600 700 800 900 1000 &quot;ave126&quot; (a) = 128 (b) = 126 Figure 1: Averages of the random numbers generated for = 128 and = 126. The gures on the bottom row are zoomed versions of the gures on top in order to illustrate the oscillations. 3...
View Full Document

This note was uploaded on 09/03/2008 for the course ECSE 4510 taught by Professor Woods during the Spring '03 term at Rensselaer Polytechnic Institute.

Page1 / 3

solution01 - while that for = 128 should oscillate around....

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online