>
>r,.fac"0 r
>2     2
>3     6
>4    24
>5   120
>6   720
>7  5040
>8 40320
>
>You have to make fac have rank 0 if you want it to behave like sin.

Thanks, Raul & John...

Having read ch. 20 "Rank" of the Primer (have 
understood only part of it) I gathered this:

Given
    r=. i.4
this
    <"0 r
+-------+
¦0¦1¦2¦3¦
+-------+
shows the element s of the vector, while this
    <"1 r
+-------+
¦0 1 2 3¦
+-------+
shows the vector as a whole.

Then I defined this function
    f=. fib "0
and did
    r,. f r
0 0
1 1
2 1
3 2
which worked as intended.

Further I defined this approximation of the Golden ratio
    q=. 3 : '(f y) % (f (y-1))'
    r,. q r
2          1
3          2
4        1.5
5 1.66666667
6        1.6
7      1.625
8 1.61538462
which produced this table, also looking correct.

One of the next steps will probably involve formatting the table.

To give you an idea what I'm aiming at, here's 
some code which uses the "echo" ( and therefore 
will only work in JConsole, not JWD); my wish has been
(1) to get rid of "echo" and
(2) produce a "loopless" version of the code (as 
I've read -people seem to stress that all the 
time- that "loopless" is one of the key concepts in J).

NB. *gra -- monad --------------------------------------------------
NB. calculate Golden ration approx (by ratio of consecutive Fibonacci numbers)
NB. throw an error for N > 23 (*fib restrainment)
gra=: 3 : 0
n=. y
nmax=. 23
if. n > nmax do.
  'Error [gra]: parameter too large (', (":n), '>', (":nmax), ')'
else.
  r=. 2 + i.(n-1)
  echo '  n  gra'
  for_j. r do.
   fn=. fib j [ fn1=. fib (j-1)
   gr=. fn % fn1
   echo (3j0":j), (16j12":gr), (8j0":fn), '/', (":fn1)
  end.
  gr=. 0.5 * (1 + %:5)
  echo ' '
  echo ' gr', (16j12":gr)
end.
)

M.





---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 090815-0, 15.08.2009
Tested on: 16.08.2009 21:12:03
avast! - copyright (c) 1988-2009 ALWIL Software.
http://www.avast.com



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

Reply via email to