Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your function to return an output with the same size and shape as the input arguments

3 vues (au cours des 30 derniers jours)
I run the code with seperately set the function and f1, f2, f3, and f4. Why I still got the orange warning. Moreover, could you please check my code. Is it correct?
clear all
%Assignment 2 Multi-Objective functions with Pareto Frontier
%Objective functions
f1 = @(x) (x(1).^4) + ((2.*x(1).^2).*x(2)) + x(2).^2 +3;
f2 = @(x) (x(1).^2-1)^2+x(2).^2-3*x(2)+1;
FITNESSFCN = @(x) [(x(1).^4) + ((2.*x(1).^2).*x(2)) + x(2).^2 + 3, (x(1).^2-1)^2+x(2).^2-3*x(2)+1];
f3 = @(x,y) x.^4 + 2*x.^2.*y + y.^2 +3;
f4 = @(x,y) (x.^2-1)^2+(y.^2)-(3*y)+1;
%Input values
nvars = 2;
A = [];
b = [];
Aeq = [];
beq = [];
nonlcon = [];
lb = [];
ub = [];
%Plot pareto frontier
options = optimoptions(@gamultiobj,'PlotFcn',{@gaplotpareto});
[x, fval] = gamultiobj(FITNESSFCN,nvars,A,b,Aeq,beq,lb,ub,nonlcon,options);
Optimization terminated: average change in the spread of Pareto solutions less than options.FunctionTolerance.
xlabel('f1')
ylabel('f2')
title('Pareto Frontier in Objective Space')
figure
hold on
% Plot Pareto Frontier in Design Space
fcontour(f3, [-30 30 -20 20], 'LineColor', 'red')
fcontour(f4, [-30 30 -20 20], 'LineColor', 'blue')
Warning: Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your function to return an output with the same size and shape as the input arguments.
scatter(x(:,1),x(:,2),10,[0 0 0],'filled','black')
xlabel('x1')
ylabel('x2')
title('Pareto Frontier in Design Space')

Réponse acceptée

Torsten
Torsten le 9 Avr 2023
f4 = @(x,y) (x.^2-1).^2+(y.^2)-(3*y)+1;
instead of
f4 = @(x,y) (x.^2-1)^2+(y.^2)-(3*y)+1;

Plus de réponses (0)

Catégories

En savoir plus sur Multiobjective Optimization dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by