Jsoftware
High-Performance Development Platform

Calculations on matrices

View: New views
12 Messages — Rating Filter:   Alert me  

Calculations on matrices

by Robert O'Boyle :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

 

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.

 

Bob

 

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: Calculations on matrices

by Kaljob Emmanuel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi,i'd like to unsubscribe from this forum,for a long
time now i've to do so but to no avail.I'd really be
happy if i stop receiving these.
  Thanks
Waiting for a favourable action
--- Robert O'Boyle <bcubed@...> wrote:

>  
>
> 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.
>
>  
>
> Bob
>
>  
>
>
----------------------------------------------------------------------
> For information about J forums see
> http://www.jsoftware.com/forums.htm
>


ALL THAT IS NECESSARY FOR EVIL TO PROSPER IS THAT  GOOD MEN DO NOTHING



      ____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: Calculations on matrices

by Roger Hui :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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 <bcubed@...>
Date: Saturday, April 26, 2008 14:26
Subject: [Jprogramming] Calculations on matrices
To: programming@...

> 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

RE: Calculations on matrices

by Sherlock, Ric :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

---Kaljob Emmanuel wrote:
> hi,i'd like to unsubscribe from this forum,for a long
> time now i've to do so but to no avail.I'd really be
> happy if i stop receiving these.
>   Thanks
> Waiting for a favourable action
Have you tried this page?
http://www.jsoftware.com/mailman/listinfo/programming
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: Calculations on matrices

by Arie Groeneveld :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Say you have:
 
NB.    v0    v1        v2
M1=: 1 2 3, 2 3 4,: 3 4 5
NB.    w0     w1       w2
M2=: 4 5 6, 5 6 7,: 6 7 8

and you want this:

t0 =: v1 f v2 f w2
t1 =: v0 f t0 f w1
t2 =:      t1 f w0

For simplicity I use * for f:

t2
  720 5040 20160


   M1 */@:* M2
720 5040 20160

But, is this what you want? :-\

=@@i


Robert O'Boyle schreef:

>  
>
> 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.
>
>  
>
> Bob
>
>  
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
>
>  
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

RE: Calculations on matrices

by Robert O'Boyle :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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: programming-bounces@...
[mailto:programming-bounces@...] 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 <bcubed@...>
Date: Saturday, April 26, 2008 14:26
Subject: [Jprogramming] Calculations on matrices
To: programming@...

> 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

Re: RE: Calculations on matrices

by Roger Hui :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Loading the script results in the following:

   caa VPA f_term;f_full_ages
|index error: BACKCAL
|   f=.f,ccc_index    {y2



----- Original Message -----
From: Robert O'Boyle <bcubed@...>
Date: Sunday, April 27, 2008 7:11
Subject: RE: [Jprogramming] Calculations on matrices
To: 'Programming forum' <programming@...>

> 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
> startingconditions. 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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: RE: Calculations on matrices

by Brian Schott :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

        I think there is a single line that wraps. But if
that is fixed, I got it to run.


On Sun, 27 Apr 2008, Roger Hui wrote:

+ Loading the script results in the following:
+
+    caa VPA f_term;f_full_ages
+ |index error: BACKCAL
+ |   f=.f,ccc_index    {y2
+
+
+
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: Calculations on matrices

by Arie Groeneveld :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Unwrap this line:

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


=@@i


Brian Schott schreef:

> I think there is a single line that wraps. But if
> that is fixed, I got it to run.
>
>
> On Sun, 27 Apr 2008, Roger Hui wrote:
>
> + Loading the script results in the following:
> +
> +    caa VPA f_term;f_full_ages
> + |index error: BACKCAL
> + |   f=.f,ccc_index    {y2
> +
> +
> +
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
>
>  
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: RE: Calculations on matrices

by Roger Hui :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Towards a more succinct solution:

sub=: 3 : 0
 'x y'=. y
 m=: {: x
 f ,: n=: ({.x) NVPA f=. y ,~ ({.x) FVPA^:_ ] 0.3
)

VPA=: 4 : 0
 y1 =.    >0{y
 y2 =. 0, >1{y
 n=: ({.x) NVPA y1
 1 0 2|:|.(y1,:n), sub"_1 }. (x ,:"1 nat_m) ;"_1 y2
)

   (naa ,: faa) -: caa VPA f_term;f_full_ages
1

It should be possible to avoid using globals.



----- Original Message -----
From: Robert O'Boyle <bcubed@...>
Date: Sunday, April 27, 2008 7:11
Subject: RE: [Jprogramming] Calculations on matrices
To: 'Programming forum' <programming@...>

> 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
> startingconditions. 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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

RE: RE: Calculations on matrices

by Robert O'Boyle :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks, Roger. I'll have a close look at this. Bob

-----Original Message-----
From: programming-bounces@...
[mailto:programming-bounces@...] On Behalf Of Roger Hui
Sent: April 28, 2008 4:07 PM
To: Programming forum
Subject: Re: RE: [Jprogramming] Calculations on matrices

Towards a more succinct solution:

sub=: 3 : 0
 'x y'=. y
 m=: {: x
 f ,: n=: ({.x) NVPA f=. y ,~ ({.x) FVPA^:_ ] 0.3
)

VPA=: 4 : 0
 y1 =.    >0{y
 y2 =. 0, >1{y
 n=: ({.x) NVPA y1
 1 0 2|:|.(y1,:n), sub"_1 }. (x ,:"1 nat_m) ;"_1 y2
)

   (naa ,: faa) -: caa VPA f_term;f_full_ages
1

It should be possible to avoid using globals.



----- Original Message -----
From: Robert O'Boyle <bcubed@...>
Date: Sunday, April 27, 2008 7:11
Subject: RE: [Jprogramming] Calculations on matrices
To: 'Programming forum' <programming@...>

> 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
> startingconditions. 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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

RE: RE: Calculations on matrices

by Robert O'Boyle :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Question for Roger

A while back, I asked if there was a way to avoid loops when undertaking
sequential calculations through a matrix. I finally had a chance to look at
your approach in detail. I see what you are doing but didn't expect it. Your
verb sub appears to move through the n by 2 matrix in the desired sequence
(results of row n calculations used in row n+1). Does this depending upon
the execution order that J undertakes when processing matrices? I was under
the impression that it was better to be explicit about execution order as
different versions of J might employ different orders (see Henry Rich's JfC
"Order of Execution in Implied Loops"). Or maybe I have it all wrong and you
are using another construct. Anyway, enlightenment on this would be great as
it opens all sorts of other doors for my software projects. Thanks in
advance

Bob

-----Original Message-----
From: programming-bounces@...
[mailto:programming-bounces@...] On Behalf Of Roger Hui
Sent: April 28, 2008 4:07 PM
To: Programming forum
Subject: Re: RE: [Jprogramming] Calculations on matrices

Towards a more succinct solution:

sub=: 3 : 0
 'x y'=. y
 m=: {: x
 f ,: n=: ({.x) NVPA f=. y ,~ ({.x) FVPA^:_ ] 0.3
)

VPA=: 4 : 0
 y1 =.    >0{y
 y2 =. 0, >1{y
 n=: ({.x) NVPA y1
 1 0 2|:|.(y1,:n), sub"_1 }. (x ,:"1 nat_m) ;"_1 y2
)

   (naa ,: faa) -: caa VPA f_term;f_full_ages
1

It should be possible to avoid using globals.



----- Original Message -----
From: Robert O'Boyle <bcubed@...>
Date: Sunday, April 27, 2008 7:11
Subject: RE: [Jprogramming] Calculations on matrices
To: 'Programming forum' <programming@...>

> 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
> startingconditions. 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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
LightInTheBox - Buy quality products at wholesale price!