Maxima:将矩阵方程转换为分配列表

Maxima: converting a matrix equation into an assignment list

我想计算一个表达式,其中包含一些符号(在矩阵 s 中给出),其值在矩阵 v:

中给出
s: matrix([a,b,c]);
v: matrix([1,2,3]);
expr: a*b+c;
ev(expr,s=v); /* not working but gives the idea of the purpose */

如何生成要传递给 ev 的正确分配列表 [a=1,b=2,c=3]

提前致谢。

您可以使用列表而不是矩阵,并为 subst

创建一个适配器
(%i1) msubst(a, b, c):=block([L: map(lambda([a0, b0], a0=b0), a, b)], subst(L, c)) $
(%i2) s   : [a,b,c] $
(%i3) v   : [1,2,3] $
(%i4) msubst(s, v, a*b+c);
(%o4)                                  5

如果需要将矩阵转为列表

(%i1) m2l(M):=block([L: []], matrixmap(lambda([e], push(e, L)), M), L) $
(%i2) s: matrix([a,b,c]) $
(%i3) m2l(s);
(%o3)                              [c, b, a]

过了好久才发了一篇。我建议使用新的解决方案而不是下面的解决方案。

在 Maxima 邮件列表上,我找到了一种方法来生成要传递给 ev 的分配列表 [a=1,b=2,c=3],使用更通用的方法(允许求解矩阵方程 A=B 双方都不知道——从来没有用火焰喷射器煮过热狗?)。前提是矩阵可以用函数

转换成列表
m2l(M):= xreduce('append,args(M)) $

传给ev的赋值列表[a=1,b=2,c=3]可以通过

获得
assign_list(s,v):= algsys(xreduce('append, args(s-v)), m2l(s)) $

因此,给定矩阵 sv 和表达式 exprexpr 可以简单地用

求值
ev(expr,assign_list(s,v));

有一个更简单的解决方案:

m2l(M):= xreduce('append,args(M)) $
massl(A,B):= map("=",m2l(A),m2l(B)) $ /*massl stands for "matrix assignment list"*/

在我们的例子中 massl(s,v) returns 分配列表 [a=1,b=2,c=3],根据需要。