fork(1) download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstdio>
  4.  
  5. using namespace std;
  6.  
  7. // Definicja funkcji
  8. double f(double x)
  9. {
  10. return 0.25 * x * x - 2;
  11. }
  12.  
  13. int main()
  14. {
  15. FILE* gnuplot = popen("gnuplot -persistent", "w");
  16.  
  17. if (!gnuplot)
  18. {
  19. cout << "Blad uruchomienia gnuplot." << endl;
  20. return 1;
  21. }
  22.  
  23. // Ustawienia wykresu
  24. fprintf(gnuplot, "set title 'Wykres funkcji f(x) = 1/4 x^2 - 2'\n");
  25. fprintf(gnuplot, "set xlabel 'x'\n");
  26. fprintf(gnuplot, "set ylabel 'f(x)'\n");
  27. fprintf(gnuplot, "set grid\n");
  28. fprintf(gnuplot, "set zeroaxis\n");
  29. fprintf(gnuplot, "set xrange [1:5]\n");
  30.  
  31. // Rysowanie wykresu
  32. fprintf(gnuplot, "plot '-' with lines lw 2 title 'f(x)'\n");
  33.  
  34. for (double x = 1.0; x <= 5.0; x += 0.01)
  35. {
  36. fprintf(gnuplot, "%f %f\n", x, f(x));
  37. }
  38.  
  39. fprintf(gnuplot, "e\n");
  40. fclose(gnuplot);
  41.  
  42. return 0;
  43. }
  44.  
Success #stdin #stdout #stderr 0.01s 5332KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
sh: 1: gnuplot: not found