Matrix algebra may help. Perhaps you can automate the production of mat and
diag below, then use matrix multiplication as illustrated below
]mat =: 3 4 $ 1 1r2 1r3 1r4 NB. rows are ratios
1 1r2 1r3 1r4
1 1r2 1r3 1r4
1 1r2 1r3 1r4
]diag =: 3 3 $ 5 0 0 0 6 0 0 0 7 0 0 0 NB. multipliers are 5 6 7
5 0 0
0 6 0
0 0 7
mp =: +/ . * NB. matrix product
diag mp rat NB. Is this what you want?
5 5r2 5r3 5r4
6 3 2 3r2
7 7r2 7r3 7r4
On 1/7/2011 2:34 PM, PackRat wrote:
> I want to create a table/array where each row is a list/vector of
> constant values multiplied by a changing value (via an implied loop).
> Here are the data:
>
> ratios=. 0 1r8 1r4 1r3 1r2 2r3 7r8 1 NB. the "constant" data
> float=. float=. x: ^: _1 NB. from "Learning J"
> (15 * i.25) NB. the "changing" data multiplier
>
> and here is what I intuitively was trying to do:
>
> float ((15 * i.25) * ratios)
>
> but I keep getting a "length error". Additionally, I'm not really sure
> how to ensure that the result of each vector multiplication becomes a
> new row in the desired array.
>
> Doing the multiplications manually one by one works fine:
>
> float (15*ratios)
> 0 1.875 3.75 5 7.5 10 13.125 15
> float (30*ratios)
> 0 3.75 7.5 10 15 20 26.25 30
>
> but when I tried "automating" that series of multipliers, J apparently
> just doesn't like my syntax above. (Of course, that still doesn't
> solve the problem of cumulatively building an array from each set of
> results.) Help would be greatly appreciated. Many thanks in advance!
>
> Harvey
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm