我在Julia中使用SymPy。我有以下代码:
using SymPy
# Define variables and function
alpha_m, alpha_r, cm, cr phi = Sym("alpha_m", "alpha_r", "cm", "cr", "phi");
X = 1+(alpha_r/alpha_m)^(1/(1-phi))*(cr/cm)^(phi/(1-phi));
现在,我想用其他变量替换几个表达式:
# New definitions
m, r = Sym("m","r");
我尝试了三种方法,但是只有最后一种可行,它为每个单独的重新定义编写了sub:
# Multiple replacement
toin = (alpha_m, alpha_r);
toout = (m/(m+r),r/(m+r));
X = subs(X,zip(toin,toout)) # NOT WORKING
X = subs(X,[alpha_m,m/(m+r),alpha_r,r/(m+r)]); # NOT WORKING
X = subs(X,alpha_m,m/(m+r))
X = subs(X,alpha_r,r/(m+r)) # WORKING
有没有办法像我在前两种方法中一样尝试一次进行多次替换?
最佳答案
您可以将第一个构造与splatting一起使用:X = subs(X,zip(toin,toout)...)