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:
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?
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.