THMMY's "Optimization Techniques" course assignments.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

54 lines
1.7 KiB

  1. function plotConvCompare(points_1, title_1, points_2, title_2, points_3, title_3, Min_point, plot_title, filename)
  2. % 3D plots a function
  3. % points: The points to plot
  4. % contur_fun: The function for contour plot
  5. % x_lim: The range for x axis. ex: [-2, 2]
  6. % y_lim: The range for y axis. ex: [0, 2]
  7. % size: The number of points for each axis
  8. % plot_title: The latex title for the plot
  9. % filename: The filename to save the plot (if exists)
  10. %
  11. global image_width,
  12. global image_height;
  13. distances_1 = sqrt((points_1(:,1) - Min_point(1)).^2 + (points_1(:,2) - Min_point(2)).^2);
  14. distances_2 = sqrt((points_2(:,1) - Min_point(1)).^2 + (points_2(:,2) - Min_point(2)).^2);
  15. distances_3 = sqrt((points_3(:,1) - Min_point(1)).^2 + (points_3(:,2) - Min_point(2)).^2);
  16. % 2D plot
  17. figure('Name', 'Convergence compare', 'NumberTitle', 'off');
  18. set(gcf, 'Position', [100, 100, image_width, image_height]); % Set the figure size
  19. title(plot_title, 'Interpreter', 'latex', 'FontSize', 16); % Title of the plot
  20. % One
  21. subplot(3, 1, 1);
  22. plot(distances_1, '-o');
  23. % Customize the plot
  24. ylabel(title_1, 'Interpreter', 'none');
  25. xlabel('Step');
  26. grid on
  27. % One
  28. subplot(3, 1, 2);
  29. plot(distances_2, '-o');
  30. % Customize the plot
  31. ylabel(title_2, 'Interpreter', 'none');
  32. xlabel('Step');
  33. grid on
  34. % One
  35. subplot(3, 1, 3);
  36. plot(distances_3, '-o');
  37. % Customize the plot
  38. ylabel(title_3, 'Interpreter', 'none');
  39. xlabel('Step');
  40. grid on
  41. % save the figure
  42. if strcmp(filename, '') == 0
  43. print(gcf, filename, '-dpng', '-r300');
  44. end
  45. end