Here is the whole script. It is a work in progress so to speak.
NB.============================================================
caa=: 210796 26450 232147 49752 10592 1693 561 54 37
caa=: caa,: 43630 270068 58591 308775 45479 13970 7722 1690 215
caa=: caa, 47948 68430 238394 109814 159203 57948 4497 409 296
caa=: caa, 751706 79933 65107 274518 72827 90617 31977 15441 5668
caa=: caa, 70536 384467 118960 160723 110852 62506 22595 6345 2693
caa=: caa, 106916 58166 285361 201097 120223 111911 41257 21271 7039
caa=: caa, 144167 173662 106170 113561 75593 93620 50022 36618 7536
caa=: caa, 649254 71984 148516 77207 75384 49065 48700 26055 13792
caa=: caa, 29656 562616 109530 34422 25562 19361 17604 19836 9661
caa=: caa, 118301 45600 616206 53199 15254 8120 5313 10964 5787
caa=: caa, 235590 158941 92356 384646 50599 9357 3239 3481 2842
caa=: caa, 19922 161637 130597 72334 219788 18960 4967 3556 1835
caa=: caa, 55634 19468 192823 106061 55066 150588 12466 2873 1253
caa =: |."2 caa
nat_m =: 13 9$ 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2
f_term =: (0.3 0.41 0.76 0.9 1 1 1 1 1) * 0.4
full_ages =: (7 8 9) - 0.2
f_full_ages =: |. 0.139 0.351 0.372 0.525 0.340 0.514 0.562 0.773
0.564 0.358 0.389 0.352
NVPA =: 4 : '(x*(y+m))%(y*(1-^-(y+m)))'
FVPA =: 4 : '((}:x)*(y+}:m))%(((}.n)*^(y+}:m))*(1-^-(y+}:m)))'
BACKCAL =: 4 : 0
n =: x
for_ccc. y
do.
m =: ccc_index { mm
f =. ccc (FVPA ^:_) 0.3
f =. f, ccc_index { y2
faa =: faa, f
n =: ccc NVPA f
naa =: naa, n
end.
)
VPA =: 4 : 0
y1 =. > 0{y
y2 =: > 1{y
m =: 0{ nat_m
faa =: ,: y1
naa =: ,: (0{x) NVPA y1
mm =: }."2 nat_m
(,naa) BACKCAL (}."2 x)
naa =: |. naa
faa =: |. faa
)
caa VPA f_term;f_full_ages
NB.==================================================
The first bit is just data entry. VPA calls NVPA to set up the starting
conditions. Then it calls BACKCAL which undertakes the row by row
calculations, the main one (FVPA) being an iteration to find roots. You will
note that I have declared a number of variables global. This is to speed up
performance because this routine is part of a bigger optimization which
loops through these calculations literally thousands of times. As I stated
in my previous post, I initially configured BACKCAL to work with insert /.
This was OK if nat_m is a list, not a matrix as it is here. Also, the speed
gains were not great. Anyway, this code works. I'd just like to know if
there is a way in J to really speed up the row by row processing.
Bob
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Roger Hui
Sent: April 26, 2008 7:17 PM
To: Programming forum
Subject: Re: [Jprogramming] Calculations on matrices
If you post the function with the FOR_MATRIX loop
it'd be helpful for figuring out exactly what you mean.
----- Original Message -----
From: Robert O'Boyle <[EMAIL PROTECTED]>
Date: Saturday, April 26, 2008 14:26
Subject: [Jprogramming] Calculations on matrices
To: [email protected]
> I have to apply a set of equations to each row of a matrix. For
> instance,the first row is y of the verb while the second row is
> x. The results of the
> verb are then used with the third row and so on through the
> matrix. At the
> same time, the verb is accessing another matrix which the same
> dimension as
> the first one, with each row of it being used by the verb as the
> calculations move through the matrix. I have tried using v /
> which is great
> but I can't see how the verb will access the rows of the second
> matrix. I am
> currently using the FOR_MATRIX .. DO.END structure which works
> fine but I
> wonder if there is a more efficient way in J to undertake recursive
> calculations through rows of a matrix in this manner.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm