Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

matlab optimization code not working

2 visualizaciones (últimos 30 días)
Briana Canet
Briana Canet el 18 de Sept. de 2023
Cerrada: Briana Canet el 20 de Sept. de 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 comentarios
Dyuman Joshi
Dyuman Joshi el 18 de Sept. de 2023
The code works, see the edit above.
Torsten
Torsten el 18 de Sept. de 2023
Editada: Torsten el 18 de Sept. de 2023
The result is correct: For arbitrary x1, x2 = 0 gives the pareto optimum for F(w).

Respuestas (0)

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by