【发布时间】:2021-04-06 07:21:42
【问题描述】:
我的代码类似于下面的代码,其中一个函数的参数取决于循环迭代,在每次迭代后绘制。我想用名称 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);"
【问题讨论】: