Taking a matlab class and sometimes need help

  • Thread starter cindyc
  • Start date
Hi everyone, i've found helpful comments on this forum so far and am new to blogging so... please be nice:) Anyway sometimes i need help with matlab code. I like writing myself but know i can use comments to make the code better/ more elegant. So here goes:
This is a simulation for a single server overlapping time intervals. Intervals are exponentially generated random variables (poisson process). I want time passed closing and average time spent in the store. Is it doing what i want and can I make it better. Thanks

oh P.S. X(lam) is a function i call up to generate the exp. random variable.

A=zeros(1,10); D=zeros(1,10); Tp = 0; % time past close
avg = 0; % average time in the system
t=0; na=0; nd=0; n = 0; %start time, number of arrivals, num of departures, num of cust
ta = -log(rand)/lam; %first arrival
td = inf; % departure time unending
T = 8; % Store open for 8 hours

while ta <= T
if ta<=td
t = ta; n= n+1;
na = na + 1; A(na) = t; ta = t + X(lam);
if n ==1
td = t + X(lam);
t = td; n = n-1; nd = nd + 1; D(nd) = t; %departures
if n> 0
td = t + X(lam)
td = inf;
while n>0 % clearing the queue
t = td
nd= nd + 1
D(nd) = t;
n = n-1
td = t + X(lam);

Tp = max (t - T, 0);
avg = mean(D-A);
disp([Tp avg])

Want to reply to this thread?

"Taking a matlab class and sometimes need help" You must log in or register to reply here.

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving