Maxima 将当前循环迭代添加到文件名
Maxima add current loop iteration to filename
我的代码类似于下面的代码,其中在每次迭代后绘制了一个函数,该函数的参数取决于循环迭代。我想用名称 trigplot_i.ps 保存绘图,其中 i 是迭代次数,但不知道如何保存。
我试过 trigplot_"i".ps 但没用,也找不到如何将 i 转换为字符串的方法。
我是初学者,非常欢迎任何帮助。
f(x) := sin(x);
g(x) := cos(x);
for i:1 thru 10 do
(plot2d([i*f(x), i*g(x)], [x,-5,5],[legend,"sin(x)","cos(x)"],
[xlabel,"x"],[ylabel,"y"],
[ps_file,"./trigplot_i.ps"],
[gnuplot_preamble,"set key box spacing 1.3 top right"])
);
编辑后的代码报错:
f(x) := sin(x);
g(x) := cos(x);
for i:1 thru 10
do block([myfile],
myfile: sconcat("./trigplot_", i, ".ps"),
printf (true, "iteration ~d, myfile = ~a~%", myfile),
plot2d([i*f(x), i*g(x)], [x,-5,5],[legend,"sin(x)","cos(x)"],
[xlabel,"x"],[ylabel,"y"],
[ps_file, myfile],
[gnuplot_preamble,"set key box spacing 1.3 top right"])
);
错误:
"声明:参数必须是一个符号;找到"./trigplot_1.ps
- 一个错误。
要调试此尝试:debugmode(true);"
看起来不错。要构建文件名,请尝试:sconcat("./trigplot_", i, ".ps")
或者您也可以尝试:printf(false, "./trigplot_~d.ps", i)
。我的建议是将其作为循环中的一个单独步骤,然后您可以在对 plot2d
的调用中使用它,例如:
for i:1 thru 10
do block ([myfile],
myfile: sconcat("./trigplot_", i, ".ps"),
printf (true, "iteration ~d, myfile = ~a~%", i, myfile),
plot2d (<stuff goes here>, [ps_file, myfile], <more stuff>));
编辑:修复了 printf
中的错误(省略参数 i
)。
我的代码类似于下面的代码,其中在每次迭代后绘制了一个函数,该函数的参数取决于循环迭代。我想用名称 trigplot_i.ps 保存绘图,其中 i 是迭代次数,但不知道如何保存。
我试过 trigplot_"i".ps 但没用,也找不到如何将 i 转换为字符串的方法。
我是初学者,非常欢迎任何帮助。
f(x) := sin(x);
g(x) := cos(x);
for i:1 thru 10 do
(plot2d([i*f(x), i*g(x)], [x,-5,5],[legend,"sin(x)","cos(x)"],
[xlabel,"x"],[ylabel,"y"],
[ps_file,"./trigplot_i.ps"],
[gnuplot_preamble,"set key box spacing 1.3 top right"])
);
编辑后的代码报错:
f(x) := sin(x);
g(x) := cos(x);
for i:1 thru 10
do block([myfile],
myfile: sconcat("./trigplot_", i, ".ps"),
printf (true, "iteration ~d, myfile = ~a~%", myfile),
plot2d([i*f(x), i*g(x)], [x,-5,5],[legend,"sin(x)","cos(x)"],
[xlabel,"x"],[ylabel,"y"],
[ps_file, myfile],
[gnuplot_preamble,"set key box spacing 1.3 top right"])
);
错误: "声明:参数必须是一个符号;找到"./trigplot_1.ps - 一个错误。 要调试此尝试:debugmode(true);"
看起来不错。要构建文件名,请尝试:sconcat("./trigplot_", i, ".ps")
或者您也可以尝试:printf(false, "./trigplot_~d.ps", i)
。我的建议是将其作为循环中的一个单独步骤,然后您可以在对 plot2d
的调用中使用它,例如:
for i:1 thru 10
do block ([myfile],
myfile: sconcat("./trigplot_", i, ".ps"),
printf (true, "iteration ~d, myfile = ~a~%", i, myfile),
plot2d (<stuff goes here>, [ps_file, myfile], <more stuff>));
编辑:修复了 printf
中的错误(省略参数 i
)。