I "think" I am getting closer to a better model. So thanks especially to
Joe and Ric. My suspicion is that the initial positions of the turtles were
set by -z values when they should have been +z values and the pitch
adjustment (pt in the code) was negative relative to the desired pitch
adjustment relative to tgsjhs. The script below makes those to adjustments.

But the paths that the turtles/pendula take are still quite chaotic in
their own correct plane and I suspect the scaling of the turtle steps is a
factor. The default value in tgsjhs.ijs is as follows.

Step_scale =: %100

In the original python code pendula are always advanced forward by the
following amount and I suspect that 25 is critical, but I cannot figure out
how it matters. (Btw, notice that the value 25 appears twice in the script
below, but I really have no sense of what it should be.)

length * 25

So my question now is what is the derivation of the 25?  And, Joe, if you
can readily process the original Python example with values different from
25 and characterize the results, I would appreciate it.

NB.
http://code.activestate.com/recipes/577553-pendulum-simulation-with-turtle/

NB. to execute load this after loading tgsjhs.ijs; enter something like:
main 4

coclass'tgsj'
coinsert'jhs'

GA =: 9.80665 NB. Gravitational Acceleration (meters per second squared)

main =: 3 : 0
NTurtles =: y
PENDING=: ''
NUMBER=: 0
NB. Step_scale =: %100
init ''
cs''
initTurtles y
pu ''

setlength =. <.@-: + 3 +i.
length =. setlength y
xdist =. * i:@-:@<:
ngol =: - GA % length    NB. Negative G over L
total_time =: 0.0        NB. Seconds
angle =: 1.0             NB. Initial angle of pendulum (radians)
sinAngle =. sin angle
goto 25 * (xdist,.-@setlength,.sinAngle * setlength) y
pd''
speed =: 0.0             NB. Initial angular velocity (radians/second)
time_step =: 0.05        NB. Seconds
while. total_time < 10.0 do.
NB. while. total_time < 0.15 do. NB. this is for testing only
    total_time =: total_time + time_step
    speed =: speed + ngol * (sin angle) * time_step
    angle =: angle + speed * time_step
    pt -dfr angle + pi -rfd }:2{"1 Heading
    fd 25 * length
    smoutput (2{"1 Heading),.Position NB. this is for testing only

end.
)




On Thu, May 15, 2014 at 1:20 PM, Brian Schott <[email protected]>wrote:

> At the following link I found a pendulum simulation that is an several
> places on the web. It simulates a single 9 meter long pendulum by
> repeatedly sending the turtle/pendulum fd by the amount 25*9, and adjusting
> the heading angle before each such forward amount by a function of the
> previous heading angle (sine of the angle, actually) and its new speed,
> which itself is a function  of the previous speed.
>
> http://code.activestate.com/recipes/577553-pendulum-simulation-with-turtle/
>
> I have translated the code at that link to J, which you can run by typing
> in simply `main''` after entering the code in a J session.
>
> GA =: 9.80665 NB. Gravitational Acceleration (meters per second squared)
> NB. FORM = 'Time={:6.3f}, Angle={:6.3f}, Speed={:6.3f}'
>
>
> sin =: 1&o.
> pi =: 1p1
> main =: 3 : 0
>     length =: 9.0            NB. Of pendulum (meters)
>     ngol =: - GA % length    NB. Negative G over L
>     total_time =: 0.0        NB. Seconds
>     angle =: 1.0             NB. Initial angle of pendulum (radians)
>     speed =: 0.0             NB. Initial angular velocity (radians/second)
>     time_step =: 0.05        NB. Seconds
>     while. total_time < 30.0 do.
>         total_time =: total_time + time_step
>         speed =: speed + ngol * (sin angle) * time_step
>         angle =: angle + speed * time_step
>     smoutput 'setheading :',":angle + pi
>     smoutput 'forward,dot :',": 25 10 * length
>    end.
> )
>
> I have also translated it so that it will work with tgsjhs.ijs which is on
> the jwiki, but I am having problems with this version because the turtles
> are making big jumps, instead of small ones, and there is no oscillation in
> their patterns. I am particularly suspicious of my scaling of the forward
> steps and that I am not familiar with the dot() function used in the python
> version. Does anyone know what the dot() function does?
>
>
> The version below has to be loaded after a fresh version of tgsjhs.ijs
> from jwiki, and can be run then with: main 4.
>
>
>
> http://www.jsoftware.com/jwiki/BrianSchott/code/turtleGraphics/tgsjhs
>
> NB.
> http://code.activestate.com/recipes/577553-pendulum-simulation-with-turtle/
>
> NB. to execute load this after loading tgsjhs.ijs; enter something like:
> main 4
>
> coclass'tgsj'
> coinsert'jhs'
>
> GA =: 9.80665 NB. Gravitational Acceleration (meters per second squared)
>
> main =: 3 : 0
> NTurtles =: y
> PENDING=: ''
> NUMBER=: 0
> init ''
> cs''
> initTurtles y
> pu ''
>
> setlength =. <.@-: + 3 +i.
> length =. setlength y
> xdist =. * i:@-:@<:
> ngol =: - GA % length    NB. Negative G over L
> total_time =: 0.0        NB. Seconds
> angle =: 1.0             NB. Initial angle of pendulum (radians)
> sinAngle =. sin angle
> goto 25 * (xdist,.-@setlength,.sinAngle * -@setlength) y
> pd''
> speed =: 0.0             NB. Initial angular velocity (radians/second)
> time_step =: 0.05        NB. Seconds
> NB. while. total_time < 10.0 do.
> while. total_time < 0.15 do. NB. this is for testing only
>     total_time =: total_time + time_step
>     speed =: speed + ngol * (sin angle) * time_step
>     angle =: angle + speed * time_step
>     pt dfr angle + pi -rfd }:1{"1 Heading
>     fd 25 * length
>     smoutput ({:"1 Heading),.Position NB. this is for testing only
>
> end.
> )
>
> Thanks,
>



-- 
(B=)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to