How to assign the output results at the loop for in maxima to different variables

I want to save the output of this for to different variables, for example, matrix A1, A2 and A3.

B:matrix([0,-%pi/2,theta[1],0],[0,%pi/2,0,d[2]],[a[3],0,theta[3],0]);

D:matrix_size(B);

for i: 1 step 1 thru D[1] do
display(A:matrix([cos(B[i,3]),(-sin(B[i,3])*cos(B[i,2])), sin(B[i,3])*sin(B[i,2]), 
    B[i,1]*cos(B[i,3])],[sin(B[i,3]),cos(B[i,3])*cos(B[i,2]),-
    cos(B[i,3])*sin(B[i,2]),B[i,1]*sin(B[i,3])],[0,sin(B[i,2]),cos(B[i,2]),B[i,4]],[0,0,0,1]));

Thanks.

Upvotes: 0

Views: 140

Answers (2)

Robert Dodier
Robert Dodier

Reputation: 17575

Just use subscripted variables.

for i:1 thru 3 do A[i] : <complicated stuff>;

Constructing variables A1, A2, A3 ... is possible but considered bad form.

Upvotes: 1

slitvinov
slitvinov

Reputation: 5768

You can use operator ::

B:matrix([0,-%pi/2,theta[1],0],[0,%pi/2,0,d[2]],[a[3],0,theta[3],0]);

D:matrix_size(B);

for i: 1 step 1 thru D[1] do
concat('A, i) :: matrix([cos(B[i,3]),(-sin(B[i,3])*cos(B[i,2])), sin(B[i,3])*sin(B[i,2]), 
  B[i,1]*cos(B[i,3])],[sin(B[i,3]),cos(B[i,3])*cos(B[i,2]),-
  cos(B[i,3])*sin(B[i,2]),B[i,1]*sin(B[i,3])],[0,sin(B[i,2]),cos(B[i,2]),B[i,4]],[0,0,0,1]);

Upvotes: 0

Related Questions