【发布时间】:2011-12-31 15:23:49
【问题描述】:
我通过以下方式将列表转换为 Maxima 中的矩阵:
DataL : [ [1,2], [2,4], [3,6], [4,8] ];
DataM: apply('matrix,DataL);
如何做到这一点?如何将给定的矩阵 DataM 转换为列表 DataL ?
【问题讨论】:
标签: symbolic-math maxima computer-algebra-systems
我通过以下方式将列表转换为 Maxima 中的矩阵:
DataL : [ [1,2], [2,4], [3,6], [4,8] ];
DataM: apply('matrix,DataL);
如何做到这一点?如何将给定的矩阵 DataM 转换为列表 DataL ?
【问题讨论】:
标签: symbolic-math maxima computer-algebra-systems
我知道这已经很晚了,但值得一提的是,有一个更简单的方法。
my_matrix : matrix ([a, b, c], [d, e, f]);
my_list : args (my_matrix);
=> [[a, b, c], [d, e, f]]
【讨论】:
我远不是 Maxima 专家,但自从 you asked me to look at this question 之后,我在快速浏览了 documentation 后就知道了。
首先,查看documentation on matrices 只产生了一种将矩阵转换为列表的方法,即list_matrix_entries。但是,这将返回条目的平面列表。要获得嵌套列表结构,类似以下工作
DataL : [[1, 2], [2, 4], [3, 6], [4, 8]]; /* Using your example list */
DataM : apply('matrix, DataL); /* and matrix */
DataML : makelist(list_matrix_entries(row(DataM, i)), i, 1, 4);
is(DataML = DataL); /* true */
这很笨拙,可能效率低下。使用 Maxima 中的底层 Lisp 结构(类似于我更熟悉的 Mathematica),您可以使用 part 检查 DataL 和 DataM 的头部:
part(DataL, 0); /* [ */
part(DataM, 0); /* matrix */
然后在两个结构体之间进行转换,可以使用substpart
is(substpart(matrix, DataL, 0) = DataM); /* true */
is(substpart( "[", DataM, 0) = DataL); /* true */
在0 级别使用substpart 与使用apply 几乎相同,但它不仅仅适用于列表。
【讨论】: