MM1 Q Math C&D exampmle

MM1 Q Math C&D exampmle - { t <- Td Nd...

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

View Full Document Right Arrow Icon
#***************** #****Tutorial **** #***************** ## MM1 Code MM1 <- function(ArriveRate,DepartRate,random) { cat("WELCOME TO THE C&D","\n") cat("\n") Na <- 0 Nd <- 0 n <- 0 t <- 0 To <- 7.5-ArriveRate*log(random[1]) random <- random[2:length(random)] infinit <- 1000000 Td <- infinit Ta <- To T <- 8.5 flag <- 1 ArrivalTime <- Ta DepartureTime <- NULL Q=NULL while (flag>=1) { flag1<-0 flag2<-0 flag3<-0 if (Ta <= Td & Ta <= T) { t <- Ta Na <- Na + 1 n <- n + 1 cat("Arrival at time, ",Ta,"\n") Q <- rep(1,length(Q)+1) Ta <- t - ArriveRate*log(random[1]) random <- random[2:length(random)] if (Ta < T) { ArrivalTime <- cbind(ArrivalTime, Ta) }
Background image of page 1

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

View Full DocumentRight Arrow Icon
if (n==1) { Td <- t - DepartRate*log(random[1]) random <- random[2:length(random)] DepartureTime <- cbind(DepartureTime, Td) } flag1 <- 1 } else if (Td <= Ta & Td <= T)
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: { t &lt;- Td Nd &lt;- Nd + 1 n &lt;- n - 1 if (n&gt;0) { cat(&quot;Departure at time, &quot;,Td,&quot;\n&quot;) Td &lt;- t - DepartRate*log(random[1]) random &lt;- random[2:length(random)] DepartureTime &lt;- cbind(DepartureTime, Td) Q &lt;- Q[2:length(Q)] } else { cat(&quot;Departure at time, &quot;,Td,&quot;\n&quot;) Td &lt;- infinit Q &lt;-NULL } flag2&lt;-1 } else if (min(Ta,Td)&gt;T &amp; n&gt;0) { t &lt;- Td Nd &lt;- Nd + 1 n &lt;- n - 1 if (n&gt;0) { cat(&quot;Departure at time, &quot;,Td,&quot;\n&quot;) Td &lt;- t - DepartRate*log(random[1]) random &lt;- random[2:length(random)] DepartureTime &lt;- cbind(DepartureTime, Td) Q &lt;- Q[2:length(Q)] } else { cat(&quot;Departure at time, &quot;,Td,&quot;\n&quot;) Td &lt;- infinit Q &lt;-NULL } flag3&lt;-1 } flag &lt;- flag1+flag2+flag3 cat(&quot;The Q is. ..&quot;,Q,&quot;\n&quot;) ANSWER &lt;- readline(&quot; &quot;) #stall program } return(DepartureTime-ArrivalTime) } output&lt;-MM1(0.1,0.2,runif(500))...
View Full Document

This note was uploaded on 11/16/2010 for the course STAT 340 taught by Professor Xu(sunny)wang during the Spring '09 term at Waterloo.

Page1 / 3

MM1 Q Math C&amp;D exampmle - { t &amp;amp;lt;- Td Nd...

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