THMMY's "Optimization Techniques" course assignments.
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

33 satır
1.1 KiB

  1. function plotContour(fun, x_lim, y_lim, size, plot_title, filename)
  2. % plot the contour of a function
  3. % fun: The function to plot
  4. % x_lim: The range for x axis. ex: [-2, 2]
  5. % y_lim: The range for y axis. ex: [0, 2]
  6. % size: The number of points for each axis
  7. % plot_title: The latex title for the plot
  8. %
  9. % Generate a grid for x and y
  10. x_space = linspace(x_lim(1), x_lim(2), size);
  11. y_space = linspace(y_lim(1), y_lim(2), size);
  12. [X, Y] = meshgrid(x_space, y_space);
  13. % Evaluate the function on the grid
  14. Z = fun(X, Y);
  15. % Contour
  16. figure('Name', 'Contours of f(x,y)', 'NumberTitle', 'off');
  17. set(gcf, 'Position', [100, 100, 960, 960]); % Set the figure size
  18. contour(X, Y, Z);
  19. % Customize the plot
  20. xlabel('x'); % Label for x-axis
  21. ylabel('y'); % Label for y-axis
  22. title(plot_title, 'Interpreter', 'latex', 'FontSize', 16); % Title of the plot
  23. colorbar;
  24. % save the figure
  25. if strcmp(filename, '') == 0
  26. print(gcf, filename, '-dpng', '-r300');
  27. end
  28. end