フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

matlab optimization code not working

2 ビュー (過去 30 日間)
Briana Canet
Briana Canet 2023 年 9 月 18 日
閉鎖済み: Briana Canet 2023 年 9 月 20 日
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 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 9 月 18 日
The code works, see the edit above.
Torsten
Torsten 2023 年 9 月 18 日
編集済み: Torsten 2023 年 9 月 18 日
The result is correct: For arbitrary x1, x2 = 0 gives the pareto optimum for F(w).

回答 (0 件)

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by