Nested for-statements in Maxima
- Subject: Nested for-statements in Maxima
- From: James Amundson
- Date: Thu, 20 Nov 2003 10:23:48 -0600
On Wed, 2003-11-19 at 08:33, Barton Willis wrote:
> 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);
An even simpler solution is to use genmatrix:
(C2) one[i,j]:=i+j;
(D2) one := i + j
i, j
(C3) genmatrix(one,2,2);
[ 2 3 ]
(D3) [ ]
[ 3 4 ]
(C4) two[i,j]:=i-j;
(D4) two := i - j
i, j
(C5) genmatrix(two,4,4);
[ 0 - 1 - 2 - 3 ]
[ ]
[ 1 0 - 1 - 2 ]
(D5) [ ]
[ 2 1 0 - 1 ]
[ ]
[ 3 2 1 0 ]
--Jim