J Labs

Spirals

The function ; links its vector arguments to form a list of boxed vectors. Thus:


In [ ]:
load 'trig'

In [ ]:
cos 1                   NB. Cosine of  radian arguments

In [ ]:
cos 1 2 3.14

In [ ]:
cosd 0 30 45 60         NB. Cosine of degree arguments

In [ ]:
(sind 0 30 45 60) ; (cosd 0 30 45 60)

In [ ]:
circle=: cosd ; sind

In [ ]:
circle 0 30 45 60

The function circle yields coordinates of points on a unit circle, as may be seen in the following plot for angles from 0 to 12 degrees:

After viewing the plot, press Alt F4 to return focus from the plot window:


In [ ]:
load 'plot'

In [ ]:
plot circle 10 * 0 1 2 3 4 5 6 7 8 9 10 11 12

(3 of 5) INTEGER LISTS

The function i. produces a vector of the first non-negative integers, as in the next example shown.

Note that the plot of the circle is correct according to the scales of the plot, although it may appear flattened because of the aspect ratio of the screen.


In [ ]:
i. 13     NB. First 13 non-negative integers

In [ ]:
plot circle i. 270

(4 of 5) THREE DIMENSIONS

The function:

```spiral=: cosd ; sind ; %:```

produces tables of vectors in three dimensions, the z coordinate being the square root (%:) of the argument. For example:


In [ ]:
spiral=: cosd ; sind ; %:

In [ ]:
spiral 0 10 20 30

In [ ]:
plot spiral i. 1000

(5 of 5) NON-CIRCULAR SPIRALS

Functions other than sine and cosine may be used. In particular, the exponential (^) applied to negative arguments can be used to produce a decaying spiral. For example:


In [ ]:
decay=: ^@(%&_500)

In [ ]:
desin=: decay * sind

In [ ]:
decos=: decay * cosd

In [ ]:
despi=: decos ; desin ; %:

In [ ]:
plot despi i. 1000

End of Lab


In [ ]: