[向量替换

问题描述 投票:2回答:1

我在wxmaxima中有一个巨大的动态系统,我需要做一些矢量替换,但最终会得到一些疯狂的结果。这是我需要做的:

forces:[
    F1=[x1,y1,z1],
    F2=[x2,y2,z2]
];
equations:[F3=-F2];
subst(forces,subst(equations,F1+F3));

我正在寻找的结果只是一个简单的[x1+x2,y1+y2,z1+z2],但我却得到了:[[x1-x2,x1-y2,x1-z2],[y1-x2,y1-y2,y1-z2],[z1-x2,z1-y2,z1-z2]]

有什么建议吗?

maxima wxmaxima
1个回答
1
投票

好的,这很令人困惑,尽管我现在知道发生了什么。

subst是串行(一对一)替换,因此subst([F1 = ..., F2 = ...], ...)等效于subst(F2 = ..., subst(F1 = ..., ...))。也就是说,先用F1代替,然后用F2替代结果。

但是subst(F1 = [x1, y1, z1], F1 - F2)的结果是[x1 - F2, y1 - F2, z1 - F2]。现在您可以看到,如果将F2替换为该内容,将会发生什么-您将得到混乱的嵌套列表结果。

我认为如果您尝试psubst(并行替换),您将获得预期的结果。

(%i2) forces:[
    F1=[x1,y1,z1],
    F2=[x2,y2,z2]
];
(%o2)        [F1 = [x1, y1, z1], F2 = [x2, y2, z2]]
(%i3) equations:[F3=-F2];
(%o3)                      [F3 = - F2]
(%i4) subst(equations, F1 + F3);
(%o4)                        F1 - F2
(%i5) psubst (forces, %o4);
(%o5)              [x1 - x2, y1 - y2, z1 - z2]
(%i6) psubst(forces, subst(equations, F1 + F3));
(%o6)              [x1 - x2, y1 - y2, z1 - z2]
© www.soinside.com 2019 - 2024. All rights reserved.