On Sat, Nov 28, 2015 at 3:27 PM, John Baker <[email protected]>
wrote (with some blank lines removed):
> A nasty combination of too much recent programming in loopy languages
> combined with advancing age has dulled my memory of how to properly grow a
> rate adjusted series without looping. The following solves my immediate
> problem but my sense of J aesthetics is appalled.
>
> Would anyone care to provide a more J'ey solution.
>
> AccumulateSeries2=:4 : 0
> NB.*AccumulateSeries2 v-- accumulate rate adjusted current and
> NB. future series credits and charges.
> NB.
> NB. dyad: nl =. ia AccumulateSeries2 ntSeriesGrowth
> NB.
> NB. sr=. ((5#100),0 0 _80 0 0 200 200) ,: (6#1),6$1.001667 0.98 1
> NB. (3 AccumulateSeries2 sr) ,: 0{sr
>
> 'sv gr'=. y
>
> NB. forward last actuals and accumulate rate adjusted
> pv=. x {. sv
> cv=. (_1 {. pv) , x }. sv
> cg=. (_1 {. x {. gr) , x }. gr
> for_j. i.<:#cv do.
> cv=. (((>:j){cv) + (j{cg) * j{cv) (>:j)} cv
> end.
>
> pv , }. cv
> )
I am actually a little puzzled here also.
But first, let me show you where I am at.
First, I decided to clean up your explicit definition. I've also left
out the comments, since this is just an intermediate form:
as3=:4 : 0
'sv gr'=. y
for_j. (x-1)}.i.<:#sv do.
sv=. (((>:j){sv) + (j{gr) * j{sv) (>:j)} sv
end.
)
This is a work-alike:
3 (as3 -: AccumulateSeries2) sr
1
So then, I tried taking a step back and approaching this analytically,
and here, I seem to be accumulating some error:
sr2=: 2}."1 sr
+/\({.sr2) * */\ {:sr2
100 200 300 300 300 221.469 221.469 221.469 414.19 606.911
So I'm not thinking about this quite right, myself.
I'll come back to this in a few hours and maybe I'll see where I went wrong.
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm