【问题标题】:How to plot a best-fit curve found using gsl_multifit_linear function in C++?如何绘制在 C++ 中使用 gsl_multifit_linear 函数找到的最佳拟合曲线?
【发布时间】:2021-06-20 06:43:26
【问题描述】:

我有一组 x 和 y 值,我使用 gsl_multifit_linear 函数将它们拟合到多项式上。我想使用 gnuplot 将最佳拟合曲线绘制到散点图上。现在,我只知道如何自己绘制点:

FILE *gnuplot = popen("gnuplot", "w");
fprintf(gnuplot, "plot '-'\n");
for (int i = 0; i < num_points; i++)
   fprintf(gnuplot, "%g %g\n", xvals[i], yvals[i]);
printf(gnuplot, "e\n");
fflush(gnuplot);

【问题讨论】:

  • 这看起来不像是编程问题。您正在寻找如何使用 gnuplot 的帮助。
  • 写下你想要的 gnuplot 脚本。然后修改您的代码以模仿脚本。无论如何,不​​知道拟合多项式的参数,是度等,不可能给你更具体的答案/建议。

标签: c++ gnuplot gsl


【解决方案1】:

先绘制函数,再绘制数据:

fprintf(gnuplot, "plot x*x, '-'\n");

这里我假设函数只是 x*x。 或者,将这些点保存到一个临时文件中,然后以通常的 gnuplot 方式以相对于数据的任何顺序绘制它。

【讨论】:

    猜你喜欢
    • 2011-07-18
    • 2017-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-25
    • 1970-01-01
    相关资源
    最近更新 更多