Henry et. al.,
At first glance, I started to reply to Michael's message with
a moving average. But I decided to take the FORTRAN routine as
a specification and NOT make the assumption that you did - that
it was intended that successive elements depend on previous
calculations. Then I had a hard time imagining just what was
wanted - partly because it was decades ago that I last used
FORTRAN (pre Fortran 77) and I'm unclear on what the array "a"
consists of. I have looked a little at FORTRAN tutorials on
the net, but lacking a compiler to experiment with, didn't
achieve much/any understanding ... Isn't that the wonderful
thing about j, experimentation! -- and the fact that we tend
to use concrete examples as you, Devon, and Brian did in your
nice demos.
Seems to me that a is a "mixed counting origin" matrix (that
in itself feels strange...) of shape T by 100 - and It looks
like some integer T and a length 100 vector is supplied as
input to avg1d - I got stuck wondering what the elements are
in the matrix "a" operated on in the do loops - Perhaps you are
right and the subroutine is an incorrect specification of what
is wanted (maybe a good reason not to use such loopy code as
problem specification language...)
In any case, I hope that Michael will let the forum know
whether or not his questions were answered - or provide more
concrete examples of what the data in/out looks like.
- joey
At 09:14 -0400 2006/05/30, Henry Rich wrote:
A J program might be:
upd =: (<<<0 _1)}"1~ 3 (3 %~ +/)\"1 ]
This program does not exactly reproduce the results of your FORTRAN
program. The FORTRAN program calculates a(t,i1) and then uses
the result of that computation to produce the result for the next
value of t. I am assuming that was unintended and you really wanted
each result value to depend only on the 2 nearest neighbors.
Henry Rich
> -----Original Message-----
> [mailto:[EMAIL PROTECTED] On Behalf Of hktyz2
Sent: Tuesday, May 30, 2006 4:17 AM
> To: [email protected]
Subject: [Jprogramming] programming with arrays?
Hello,
>
> I am a scientist mainly writing programs in Fortran and C.
Mostly, our programs are about computations on arrays. I
heard that J is an array programming language so I am
interested in that if our programs can be written in J easily.
For example, we write the following Fortran subroutine that
updates an array with an averaging operation. We update the
value of an array element with the average of its neighbors.
subroutine avg1d (T, a)
integer :: T
real, dimension (0:T, 1,100) :: a
integer :: t
integer :: i1
do i1 = 1, 100
do t = 1, T-1
a(t,i1) = (a(t-1,i1)+a(t,i1)+a(t+1,i1))/3
end do
end do
> end subroutine avg1d
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm