我有类似于下面的代码,其中在每次迭代后绘制一个参数取决于循环迭代的函数。我想用名称 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);"