Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

matlab optimization code not working

2 visualizzazioni (ultimi 30 giorni)
Briana Canet
Briana Canet il 18 Set 2023
Chiuso: Briana Canet il 20 Set 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 Commenti
Dyuman Joshi
Dyuman Joshi il 18 Set 2023
The code works, see the edit above.
Torsten
Torsten il 18 Set 2023
Modificato: Torsten il 18 Set 2023
The result is correct: For arbitrary x1, x2 = 0 gives the pareto optimum for F(w).

Risposte (0)

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by