来自maxima的嵌套for循环的数组

时间:2013-04-10 18:14:34

标签: arrays for-loop maxima

使用MAxima我想在最大值中创建11个数组。我正在尝试这样的事情:

for n:1 step 1 while n<=11 do( for j:1 while j<=21 do( if i<j then aa[n][i,j]:i+j+n));

这编译很好,但我不能按照我的意愿使用它。比方说,我希望第5个数组中的值为2,2,我尝试以下但不起作用:

aa[5][2,2];

感谢任何帮助, 本

1 个答案:

答案 0 :(得分:2)

你的代码片段缺少i或i的其他任何循环。

您可以考虑使用'genmatrix'构造矩阵,然后在n上循环以生成多个矩阵。 E.g:

foo : lambda ([i, j], if i < j then i + j + n else 0);
for n:1 thru 11 do aa[n] : genmatrix (foo, 21, 21);

然后我得到

aa[5][2, 2];
 => 0
aa[5][2, 3];
 => 10
grind (aa[10]);
 => matrix([0,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32],
   [0,0,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33],
   [0,0,0,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34],
   [0,0,0,0,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35],
   [0,0,0,0,0,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36],
   [0,0,0,0,0,0,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37],
   [0,0,0,0,0,0,0,25,26,27,28,29,30,31,32,33,34,35,36,37,38],
   [0,0,0,0,0,0,0,0,27,28,29,30,31,32,33,34,35,36,37,38,39],
   [0,0,0,0,0,0,0,0,0,29,30,31,32,33,34,35,36,37,38,39,40],
   [0,0,0,0,0,0,0,0,0,0,31,32,33,34,35,36,37,38,39,40,41],
   [0,0,0,0,0,0,0,0,0,0,0,33,34,35,36,37,38,39,40,41,42],
   [0,0,0,0,0,0,0,0,0,0,0,0,35,36,37,38,39,40,41,42,43],
   [0,0,0,0,0,0,0,0,0,0,0,0,0,37,38,39,40,41,42,43,44],
   [0,0,0,0,0,0,0,0,0,0,0,0,0,0,39,40,41,42,43,44,45],
   [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,42,43,44,45,46],
   [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,44,45,46,47],
   [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,45,46,47,48],
   [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,47,48,49],
   [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,49,50],
   [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,51],
   [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])$