从枫树写入文本文件

Write from maple to a text file

我在 maple 中有以下代码:

K:= log(x);
for j from 2 by 1 to 10 do evalf(subs(x=j,K)) end do;

我想将每个 x 和 log(x) 值写入 2 列的文本文件。 有什么帮助吗?

最简单的选择是将这些值分配给 nx2 矩阵,然后 ExportMatrix 将其分配给文本文件:

M := LinearAlgebra:-RandomMatrix(10, 2);
ExportMatrix("C:\Users\yourname\Documents\FileName.txt",
              M, target = MATLAB, mode = ascii);

John M 的回答更为笼统,因为它应该适用于从 Maple 6 开始的任何版本的 Maple,但是如果您碰巧使用的是 Maple 2015、2016 或 2017,那么您可以使用 Export 自动检测文件扩展名格式的命令:

M := Matrix(9,2):
for j to 9 do M[j,1] := j+1; M[j,2] := evalf(log(j+1)); end do:
Export("C:\Users\yourname\Documents\MyFile.csv", M);

或者如果你想要单线:

Export("C:\Users\yourname\Documents\MyFile.csv",Matrix(9,2,(i,j)->`if`(j=1,i+1,evalf(log(i+1))))):