On Fri, Aug 8, 2008 at 1:19 AM, Robert Cyr <[EMAIL PROTECTED]> wrote:
> My java test is completed in 0.45 seconds. The following rather crude
> adaptation of this code is as follows. It runs in a dismal 65 seconds .
I needed to change your code to make it work. I also added some
indentation:
inventory=: 3 : 0
NB. A discrete-time inventory system
res=:500$0
for_t. i.500 do.
res=.( 2000 profits(200,100,2,0.1,10,1,0.95,80,200))t}res
end.
dstat res NB. the orignal also shows variability using a student.
)
profits=: 4 : 0
NB. average profit during m years
'i l c h K k p s S'=.y
NB.x: number of years
NB.i: initial
m=.x[pr=.0
ps=.poissonrand l, m
for_t. i.m do.
v=. i<.t{ps NB. sales Poisson with mean l
NB. bring inventory to level S if it falls below s
NB. with probability p of receiving merchandise
r=. (S-i-v)*(s>i-v)*.p>?0
pr=.pr+(c*v)-((i-v)*h)+(r>0)*K+k*r NB. profit for day
i=.0>.i-v+r
end.
pr%m NB. average daily profit
)
inventory=: 3 : 0
NB. A discrete-time inventory system
res=:500$0
for_t. i.500 do.
res=.( 2000 profits(200,100,2,0.1,10,1,0.95,80,200))t}res
end.
dstat res
)
With this code, I get results like:
inventory''
sample size: 500
minimum: _202.154
maximum: _195.735
median: _199.305
mean: _199.259
std devn: 1.10284
skewness: 0.0776887
kurtosis: 2.97988
Does that look correct to you?
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm