필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

matlab optimization code not working

조회 수: 1 (최근 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