同时显示和保存最大值

时间:2018-12-01 07:31:58

标签: maxima

当前,我可以按如下所示以最大值显示图:

f(x) := sin(x)$
g(x) := cos(x)$

plot2d([f(x), g(x)], [x,-5,5],[legend,"sin(x)","cos(x)"],
[xlabel,"x"],[ylabel,"y"],
[gnuplot_preamble,"set key box spacing 1.3 top right"])$

并使用以下命令保存绘图:

plot2d([f(x), g(x)], [x,-5,5],[legend,"sin(x)","cos(x)"],
[xlabel,"x"],[ylabel,"y"],
[pdf_file,"./trigplot.pdf"],
[gnuplot_preamble,"set key box spacing 1.3 top right"]
)$

如何同时以最大值显示和保存图?

1 个答案:

答案 0 :(得分:0)

p2具有一个文件名和与plot2d相同的参数。

p2(file, [L])::=buildq([file, L],
  (plot2d(splice(L)),
   plot2d(splice(L), ['pdf_file, file])))$

f(x) := sin(x)$
g(x) := cos(x)$
p2("trigplot.pdf",
  [f(x), g(x)], [x,-5,5],
  [legend,"sin(x)","cos(x)"], 
  [xlabel,"x"],[ylabel,"y"],
  [gnuplot_preamble,"set key box spacing 1.3 top right"]);

它是a macro。首先,它用fileL代替。 splice(L)`被转换为参数列表。替换后,将在调用者的上下文中评估结果表达式。

您可以使用macroexpand来查看替换后的表达式。

(%i1) a: 42 $
(%i2) macroexpand(p2(file, a, b));
(%o2)           (plot2d(a, b), plot2d(a, b, ['pdf_file, file]))