This is essentially the same idea as RE's, but not extracting
arguments explicitly:
A =. _2 ]\ 1000 0.05 0 0.04 0 0.06 500 0.05 0 0.05
NB. Calculate (ending value,starting value) for each interval
*/\.@|.@(+ 1&(1}))/\.&.|.&.(0&,) A
1050 1000
1092 1050
1157.52 1092
1740.4 1657.52
1827.42 1740.4
NB. Calculate interest earned as end value - start value
-/"1 */\.@|.@(+ 1&(1}))/\.&.|.&.(0&,) A
50 42 65.52 82.876 87.0198
Henry Rich
---- "R.E. Boss" <[email protected]> wrote:
> }.({:@[ (] , *) +&{. + {:@])/\.&.|. 0 , A
> 1000 50
> 1050 42
> 1092 65.52
> 1657.52 82.876
> 1740.396 87.0198
>
>
> R.E. Boss
>
>
> > -----Oorspronkelijk bericht-----
> > Van: [email protected] [mailto:programming-
> > [email protected]] Namens Bill Harris
> > Verzonden: zaterdag 18 juli 2009 4:49
> > Aan: J Programming Forum
> > Onderwerp: [Jprogramming] Accumulation, interest, and simulation
> >
> > I've got a problem to solve, and I seem to have a mental block, even
> > though it doesn't sound that hard.
> >
> > Let's say I have an array A of rank n 2. To make it real, let {."1 A be
> > a list of deposits to a savings account, and let {:"1 A be the periodic
> > interest rate paid during that period. To simplify more, let's say each
> > item represents a year's (or at least a constant period's) entry.
> >
> > For example, let A be
> >
> > 1000.0 0.05
> > 0.0 0.04
> > 0.0 0.06
> > 500.0 0.05
> > 0.0 0.05
> >
> > I'd like to calculate the interest earned as a function of time with a
> > tacit function.
> >
> > There are many analogous problems; if I can solve this, I might even be
> > able to do a system dynamics simulation in J. (I seem to remember an
> > article in a 1990s J proceedings on doing system dynamics in J, but I
> > haven't been able to find those proceedings in quite a while.)
> >
> > I can make an auxiliary array (or stitch more columns onto A) to contain
> > both the current balance (the sum of the previous balance, the interest
> > paid from the last period, and any new deposit) and the interest being
> > earned in this period (the product of {:"1 A and the current balance).
> >
> > For example, let Aprime be
> >
> > 1000.00 0.05 1000.00 50.00
> > 0.00 0.04 1050.00 42.00
> > 0.00 0.06 1092.00 65.52
> > 500.00 0.05 1157.52 57.88
> > 0.00 0.05 1215.40 60.77
> >
> > I thought the linear recurrence essay might give me a hint, but it
> > depends upon the transformation matrix M being a constant, and this one
> > has a variable interest rate times a varying balance.
> >
> > Ideas?
> >
> > Thanks,
> >
> > Bill
> > --
> > Bill Harris http://facilitatedsystems.com/weblog/
> > Facilitated Systems Everett, WA 98208 USA
> > http://facilitatedsystems.com/ phone: +1 425 374-1845
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm