1

I am trying to understand the workings of for-do loop and trying to access the different items in the lists below:

(%i2)   thetas : [45,-45,-45,45]$
        z : [-0.5,-0.25,0.0,0.25,0.5]$
(%i3)   for c1:1 thru length(thetas) do
    (
        htop : z[c1+1],
        hbottom : z[c1],
        theta : thetas[c1]*%pi/180,
        disp(htop),
        disp(hbottom),
        disp(theta)
    );

which produces:

enter image description here

The thetas are being displayed as desired. On the other hand, during the first pass, I was expecting -0.25 assigned to htop instead of z_2 and -0.5 assigned to hbottom instead of the list with subscript 1. How can I cycle through the list z and assign (numerical) values to the hbottom and htop during each pass of the loop?

mily
  • 149
  • 1
  • 9
  • Hmm, I can't reproduce the behavior you showed. When I copy the inputs you gave, I get the expected output. What does `build_info();` report? Can you try your example in command line Maxima? – Robert Dodier Nov 08 '21 at 20:52
  • @RobertDodier here it is the output from ```(%i1) build_info(); (%o1) Maxima version: "5.43.2" Maxima build date: "2020-02-21 05:22:38" Host type: "x86_64-pc-linux-gnu" Lisp implementation type: "GNU Common Lisp (GCL)" Lisp implementation version: "GCL 2.6.12" User dir: "/home/****/.maxima" Temp dir: "/tmp" Object dir: "/home/****/.maxima/binary/5_43_2/gcl/GCL_2_6_12" Frontend: false``` and the command line produces the same result as previously obtained. – mily Nov 09 '21 at 05:25
  • Thanks, @RobertDodier. I have started using the latest version and this has fixed it for me. – mily Nov 09 '21 at 10:20

1 Answers1

1

I can't reproduce the behavior you reported. I rebuilt Maxima 5.43.2 and here's what I get.

(%i2) thetas : [45,-45,-45,45]$

(%i3) z : [-0.5,-0.25,0.0,0.25,0.5]$

(%i4) for c1:1 thru length(thetas) do
    (
        htop : z[c1+1],
        hbottom : z[c1],
        theta : thetas[c1]*%pi/180,
        disp(htop),
        disp(hbottom),
        disp(theta)
    );
                             - 0.25

                              - 0.5

                               %pi
                               ---
                                4

                               0.0

                             - 0.25

                                %pi
                              - ---
                                 4

                              0.25

                               0.0

                                %pi
                              - ---
                                 4

                               0.5

                              0.25

                               %pi
                               ---
                                4

(%o4)                         done
(%i5) build_info ();
(%o5) 
Maxima version: "5.43.2_dirty"
Maxima build date: "2021-11-08 22:31:50"
Host type: "i686-pc-linux-gnu"
Lisp implementation type: "GNU Common Lisp (GCL)"
Lisp implementation version: "GCL 2.6.12"
User dir: "/home/robert/.maxima"
Temp dir: "/tmp"
Object dir: "/home/robert/maxima/maxima-code/binary/5_43_2_dirty/gcl/GCL_2_6_12"
Frontend: false

Not sure where to go from here.

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48