发布网友 发布时间:2022-05-21 06:55
共1个回答
热心网友 时间:2023-10-18 01:34
clear;
clc;
x=[1 0 -1 3];
y=[0 0 0 0];
w=[0.1 0.5 0.2 0.2]';
f=@(var) sqrt((var(1)-x).^2+(var(2)-y).^2)*w; %var(1)=x0,var(2)=y0
[var,fval,exitflag]=ga(f,2);
x0=var(1)
y0=var(2)
plot(x,y,'o','markersize',8,'markerfacecolor','r');
hold on;
plot(x0,y0,'s','markerfacecolor','g');
for i=1:4
plot([x0 x(i)],[y0 y(i)],':');
end