Решение систем нелинейных уравнений https://www.mapleprimes.com/users/one%20man/posts?page=1
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

graphics.cpp 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include "libmathgl.h"
  2. int Mathgl_graph::animate(const state_type &coordinate, std::vector <int> vp_num, int dim_line, std::vector<std::string> equations)
  3. {
  4. state_type ranges;
  5. min_max(coordinate, ranges, dim_line);
  6. int N_var=sde->get_par_diff().nv;
  7. double N=coordinate.size()/N_var;
  8. std::vector <int> pnt_lin;
  9. //число линий в 2 раза меньше
  10. int num_lines=vp_num.size();
  11. for (int i=0;i<num_lines;i++)
  12. {
  13. for (int j=0;j<dim_line;j++)
  14. pnt_lin.push_back(dim_line*vp_num[i]-(dim_line-j));
  15. }
  16. mglFLTK gr("Draghilev");
  17. std::vector <mglData> x(N_var,N);
  18. std::vector <state_type> coord_div(N_var,coordinate);
  19. int count;
  20. for (int k=0;k<N_var;k++)
  21. {
  22. count=0;
  23. coord_div[k].erase(std::remove_if (coord_div[k].begin(), coord_div[k].end(),
  24. [&count,&k,&N_var](const double &d) {
  25. return ((count++) % N_var != k);
  26. }), coord_div[k].end());
  27. x[k].Fill(NAN);
  28. }
  29. std::vector <const char*> colour = { "b. ", "g. ", "r. ", "m. ", "y.", "q. " };
  30. std::vector <const char*> colour_lin = { "UOO", "RSS", "WDD", "BTT", "GKK", "MVV" };
  31. gr.RunThr();
  32. gr.SetSize(600,600); gr.InPlot(0,1,0,1);
  33. if (dim_line == 2)
  34. {
  35. gr.Aspect(ranges[1]-ranges[0], ranges[3]-ranges[2]);
  36. gr.SetRanges(ranges[0], ranges[1], ranges[2], ranges[3]);
  37. for(int i=0;i<N;i++)
  38. {
  39. gr.Clf();
  40. gr.Axis();
  41. for (int j=0;j<N_var;j+=dim_line)
  42. {
  43. x[j].a[i] = coord_div[j][i];
  44. x[j+1].a[i] = coord_div[j+1][i];
  45. gr.Plot(x[j], x[j+1], colour[j]);
  46. }
  47. for (int j=0;j<num_lines*dim_line;j+=2*dim_line)
  48. gr.Line(mglPoint(x[pnt_lin[j]].a[i], x[pnt_lin[j+1]].a[i]),
  49. mglPoint(x[pnt_lin[j+2]].a[i],x[pnt_lin[j+3]].a[i]),
  50. colour_lin[j/(2*dim_line)]);
  51. gr.Update();
  52. }
  53. }
  54. else if (dim_line == 3)
  55. {
  56. //Сделано как по умолчанию в octave, rotate следует перед aspect, если иначе, будет искажение
  57. gr.Rotate(60,330); gr.Grid();
  58. gr.Aspect(ranges[1]-ranges[0], ranges[3]-ranges[2], ranges[5]-ranges[4]);
  59. gr.SetRanges(ranges[0], ranges[1], ranges[2], ranges[3], ranges[4], ranges[5]);
  60. for(int i=0;i<N;i++)
  61. {
  62. gr.Clf();
  63. gr.Axis();
  64. gr.Box();
  65. //for (unsigned int k=0;k<equations.size();k++)
  66. // gr.Puts(mglPoint(ranges[1]+.5*(ranges[1]-ranges[0]), ranges[3]-.1*k*(ranges[3]-ranges[2])), equations[k].c_str());
  67. for (int j=0;j<N_var;j+=dim_line)
  68. {
  69. x[j].a[i] = coord_div[j][i];
  70. x[j+1].a[i] = coord_div[j+1][i];
  71. x[j+2].a[i] = coord_div[j+2][i];
  72. gr.Plot(x[j], x[j+1], x[j+2], colour[j]);
  73. }
  74. for (int j=0;j<num_lines*dim_line;j+=2*dim_line)
  75. gr.Line(mglPoint(x[pnt_lin[j]].a[i], x[pnt_lin[j+1]].a[i], x[pnt_lin[j+2]].a[i]),
  76. mglPoint(x[pnt_lin[j+3]].a[i], x[pnt_lin[j+4]].a[i], x[pnt_lin[j+5]].a[i]),
  77. colour_lin[j/(2*dim_line)]);
  78. gr.Update();
  79. }
  80. }
  81. return 0;
  82. }
  83. int Mathgl_graph::min_max(const state_type &coordinate, state_type &ranges, int rem)
  84. {
  85. int count;
  86. for (int k=0;k<rem;k++)
  87. {
  88. state_type temp(coordinate);
  89. count=0;
  90. temp.erase( std::remove_if (temp.begin(), temp.end(),
  91. [&count,&k,&rem](const double &d) {
  92. return ((count++) % rem != k);
  93. }), temp.end() );
  94. ranges.push_back(*std::min_element( temp.begin(), temp.end() ));
  95. ranges.push_back(*std::max_element( temp.begin(), temp.end() ));
  96. }
  97. return 0;
  98. }