mathematica.rtomstrasir ではリストを [, ] で囲むが,
Mathematica では {, } で囲む.
この関数はこの変換をおこなう.
[259] mathematica.rtomstr([1,2,3]);
{1,2,3}
[260] mathematica.rtomstr([[1,x,x^2],[1,y,y^2]]);
{{1,x,x^2},{1,y,y^2}}
もう一つ例をあげよう.
次の関数 mathematica.inverse(M) は ox_math
をよんで行列 M の逆行列を計算する関数である.
mathematica.inverse(M) は次のように r_tostr(M) を用いて
asir の行列を Mathematica 形式に変換してから
ox_execute_string で Mathematica に逆行列を計算
させている.
def inverse(M) {
P = 0;
A = mathematica.rtomstr(M);
ox_execute_string(P,"Inverse["+A+"]");
B = ox_pop_cmo(B);
C = mathematica.tree_to_string(B);
return(eval_str(C));
}
[269] M=[[1,x,x^2],[1,y,y^2],[1,z,z^2]];
[[1,x,x^2],[1,y,y^2],[1,z,z^2]]
[270] A=mathematica.inverse(M)$
[271] red(A[0][0]);
(z*y)/(x^2+(-y-z)*x+z*y)
ox_execute_string, ToExpression(Mathematica),
mathematica.tree_to_string
Go to the first, previous, next, last section, table of contents.