explicit definition using (3 : 0) will give a verb of unbounded rank so that for
fn 1 2 3 4
1 2 3 4 will be the argument (y) for fn and it becomes
+/(1+i.1 2 3 4)^5
therefore you need to extend fn from dealing with scalar y to vector y
fn1=. 3 : 0
z=. ''
for_a. y do.
z=. z, +/(1+i.a)^5
end.
)
fn1 1 2 3 4
1 33 276 1300
but J provide an alternative way using rank conjunction as already suggested by
other forum members.
fn"0[ 1 2 3 4
1 33 276 1300
fn"0 is a new verb that accept the whole vector as argument and invoke the
original verb fn by supplying scalar to verb fn, so each time fn only see a
scalar as argument.
please refer to Henry's e-book, it gives much better explanation.
Glenn M. Lewis wrote:
Hi all!
Say I have a function, like so...
fn =. 3 : 0
+/(1+i.y)^5
)
fn 839
58340773411141200
Now, I wish to make a table of all the values of 'fn' from 1 to
1000... Do I have to write a 'for' loop?
Obviously, 'fn i. 1000' doesn't work and changing 'y' to "0 y in the
function also doesn't work because of the '+/'.
This has got to be a simple thing, but I just can't quite seem to get
it.
Thanks!
-- Glenn
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
--
regards,
bill
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm