Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

matlab optimization code not working

2 Ansichten (letzte 30 Tage)
Briana Canet
Briana Canet am 18 Sep. 2023
Geschlossen: Briana Canet am 20 Sep. 2023
The following code is not working. I am not sure why. It doesn't run/create the figure.
% Define the functions
f1 = @(x1, x2) x1.^2 + x2.^2;
f2 = @(x1, x2) x2.^2 - 4*x1;
% Create a grid of values for x1 and x2
[x1, x2] = meshgrid(-5:0.1:5, -5:0.1:5); % Adjust these values as needed
% Calculate the objective functions on the grid
F1 = f1(x1, x2);
F2 = f2(x1, x2);
% Weighted average method
weights = 0.1:0.1:0.9; % Adjust these weights as needed
paretoFronts = zeros(length(weights), 2);
for i = 1:length(weights)
w = weights(i);
% Weighted sum of the objectives
F = w*F1 + (1-w)*F2;
[minF, idx] = min(F(:));
paretoFronts(i, :) = [x1(idx), x2(idx)];
end
%plot Pareto frontiers
figure;
plot(paretoFronts(:,1), paretoFronts(:,2), 'o-');
xlabel('x1');
ylabel('x2');
title('Pareto Frontiers using Weighted Average Method');
grid on;
  2 Kommentare
Dyuman Joshi
Dyuman Joshi am 18 Sep. 2023
The code works, see the edit above.
Torsten
Torsten am 18 Sep. 2023
Bearbeitet: Torsten am 18 Sep. 2023
The result is correct: For arbitrary x1, x2 = 0 gives the pareto optimum for F(w).

Antworten (0)

Diese Frage ist geschlossen.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by