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
11 次查看(过去 30 天)
显示 更早的评论
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);
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')
scatter(x(:,1),x(:,2),10,[0 0 0],'filled','black')
xlabel('x1')
ylabel('x2')
title('Pareto Frontier in Design Space')

0 个评论
采纳的回答
Torsten
2023-4-9
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;
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multiobjective Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

