Nested for-statements in Maxima



To fix this, surround  the assignments in the  inner loop with 
parenthesis:

(C1) FOR i:1 THRU 2 DO
       FOR j:1 THRU 2 DO (
         a[i,j] : i + j,
         b[i,j] : i - j);
(D1)                                 DONE
(C2) [a[1,1],a[1,2],a[2,1],a[2,2]];
(D2)                             [2, 3, 3, 4]
(C3)  [b[1,1],b[1,2],b[2,1],b[2,2]];
(D3)                            [0, - 1, 1, 0]
(C4) 

Clear?
 
Barton




"å×ÇÅÎÉÊ óÁ×ÅÎËÏ×" <savenkov@keldysh.ru>
Sent by: maxima-admin@math.utexas.edu
11/19/2003 05:58 AM
Please respond to savenkov

 
        To:     <maxima@www.ma.utexas.edu>
        cc: 
        Subject:        [Maxima] Nested for-statements in Maxima


Hello!

I'm new to Maxima, and i have a problem. I suppose the solution is simple,
but i didn't find any
in the Maxima-related docs.

I need to do something like this (in Fortran):

DO i=1,n
  DO J=1,k
      ! some assigments to the array elements here
      a(i,j) = some_function_of_ij
      b(i,j) = another_function_of_ij

  ENDDO
ENDDO

I've tried the following solution:

FOR i:1 THRU n DO
   FOR j:1 THRU k DO
      a[i,j]:some_function_of_ij,
      b[i,j]:another__function_of_ij$

but it doesn't work. Only the first assigment (a[i,j]:...) is perfomed in 
a
right way.
I think i use nested for-statements in a wrong way.

If i make only one assigment in the loop body, i.e.

FOR i:1 THRU n DO
   FOR j:1 THRU k DO
      a[i,j]:some_function_of_ij$

everything is ok.

So, what's wrong and how to do it correctly?
Just point me to the related docs or to the simple example.

Thanks a lot.

Best regards,
Gene

_______________________________________________
Maxima mailing list
Maxima@www.math.utexas.edu
http://www.math.utexas.edu/mailman/listinfo/maxima