1
我正在使用SymPy的Julia。我有以下代碼: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");
我嘗試三種方法,但只有最後一部作品,這是寫子每個單獨的重新定義:
# 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
有什麼辦法同時做多換人,就像我在嘗試前兩種方法?
可以使用Unicode,即。 (1 /(1-φ))*(cr/cm)^(φ/(1-φ))'http://julia.readthedocs.org/en/latest/manual/interacting-with-julia /?highlight = completion#tab-completion – SalchiPapa
爲了在Julia ** REPL **(和其他環境)輸入字母* phi *,開始輸入'\ ph',按下TAB鍵'自動完成到'\ phi',再次按下'TAB'將其替換爲:'φ',其他的可以像這樣組成:'\ alpha \ _r '用於'αᵣ'http:// julia。 readthedocs.org/en/latest/manual/interacting-with-julia/?highlight=completion#tab-completion –
SalchiPapa
這與我的問題有什麼關係? – luchonacho