Hi aai
This has been a great help. My initial problem was to assume different input
vectors for each year e.g. different w, pm, pr etc for each row. But you
solution works well assuming constant inputs over the projection period. I
added some more outputs and used longer names for some of the variables
(self documenting) but it basically the same as what you suggest. My next
project now is to sample from a distribution of starting n vectors.
Thanks again for your help on this - most informative!
Bob
PB=: 4 : 0 "1
n =. x
os =. y
nnn =. fff=. bbb=. ccc =. i.0, #x
out =. nnn,fff,bbb,:ccc
for_op. os do.
z =. m+f =.
pr*((*%+/@(n*w*((%*-.@:^@:-...@])m&+)@(pr*])))^:_
2:)`...@.(<&2)
op
fff =. fff, f
sb =. +/b =. pm*w*n*^-spawn_t*z
bbb =. bbb, b
ccc =. ccc, c=. (f%z)*n*(1-^-z)
r =. (sb<breakpoint){ ( ({...@$ )recruit_h),({ ~...@$ )
recruit_l
nnn =. nnn, n=. r,}: n*^-z
end.
out =. (4}."3 out),"3 nnn,fff,bbb,:ccc
)
output =: n PB 500$,:option
avg_ntot =: (+/%#)"2 +/"1 ]0{"3 output
f_full =: (+/%#)"2 >./"1 ]1{"3 output
spawn_bio =: (+/%#)"2 +/"1 ]2{"3 out
avg_yield =: (+/%#)"2 +/"1 w *"1 1 ]3{"3 output
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Aai
Sent: January 24, 2010 4:47 AM
To: Programming forum
Subject: Re: [Jprogramming] Matrix calculations
....and there's always that rank thing. So for speeding up:
PB=: 4 : 0 "1
n=. x
'd os'=. y
'w pm m pr'=. d
t1=. w*pm
z=.i.0, #x
for_op. os do.
f=. m+pr*((*%+/@(n*w*((%*-.@:^@:-...@])m&+)@(pr*])))^:_ 2:)`...@.(<&2) op
b=. +/t1*n*^-spt*f
r=. (b<bp){ ( ({...@$ )rh),({ ~...@$ ) rl
z=. z, n=. r,}: n*^-f
end.
)
This one:
ts 'n PB 1e3 $ ,: da;option'
1.13673 2127744
The one hereafter:
ts 'n PB 1e3 $ ,: da;option'
1.381286 2127744
:
> By making the anonymous explicit function tacit the globals can be made
> local again.
>
> PB=: 4 : 0 "1
> ni=. x
> 'd os'=. y
> 'w pm m pr'=. d
> t1=. w*pm
> z=.i.0, #x
> for_op. os do.
> f=. m+pr*((*%+/@(ni*w*((%...@^@-...@])m&+)@(pr*])))^:_ 2:)`...@.(<&2) op
> b=. +/t1*ni*^-spt*f
> r=. (b<bp){ ( ({...@$ )rh),({ ~...@$ ) rl
> z=. z, ni=. r,}: ni*^-f
> end.
> )
>
> I also shortened long names. :-)
>
> Use: n PB 2 $ ,: da;option
>
>
>
>
>> Sorry, more globals needed inside PB:
>>
>> PB=: 4 : 0 "1
>> ni=: x
>> 'd os'=. y
>> 'w per_mat m pr' =: d
>> z=.i.0, #w
>> for_o. os do.
>> f=. m + pr * ( 4 : 'y * x % +/ w * (f % z) * ni * 1 - ^ - z=. m + f=.
>> pr * y'^:_ 2:)`...@.(<&2) o
>> b=. +/ per_mat * w * ni * ^ - spawn_t * f
>> r=. (b<breakpoint){ ( ({...@$ )recruit_h),({ ~...@$ ) recruit_l
>> z=. z, ni=: r,}: ni * ^ - f
>> end.
>> )
>>
>> I hope this will do. :-(
>>
>>
>>
>
--
Met vriendelijke groet,
=@@i
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm