在 gnuplot 中评估用户定义的函数

evaluate user defined function in gnuplot

我经常在 gnuplot 中得到用户定义的函数,如下所示:

a=1
b=1
y(x)=(-b+sqrt(b**2-4*a*(1-x)))/(2*a)

这让我可以轻松绘制 y(x) 并将其与其他数据进行比较。但有时,我需要评估 y(x) 的特定值( 例如 y(1)),但如果我:

gnuplot> y(1)
         ^
         invalid command

我对此的蹩脚解决方案是:

gnuplot> plot y(1)
Warning: empty y range [0:0], adjusting to [-1:1]

这种方法在第一组方括号中给出了我的正确答案。但我确信在 gnuplot 中有一个我找不到的本地解决方案来评估我的用户定义函数。

所以:您知道在 gnuplot 中计算用户定义函数的任何方法吗?

您可以使用 print。如果要格式化数字,则需要 print sprintf()。例如

print y(20)
print sprintf("%5.3f",y(20))