例1
假设有以下双目标函数:
F(x)=[2+(x−3)25+x2/4]\begin{aligned} F(x) = \begin{bmatrix} 2 + (x-3)^2 \\ 5 + x^2/4 \end{bmatrix} \end{aligned}F(x)=[2+(x−3)25+x2/4]
设置目标 [3,6] 和权重 [1,1],并从 x0 = 1 开始求解目标达到问题。
12345
fun = @(x)[2+(x-3)^2;5+x^2/4];goal = [3,6];weight = [1,1];x0 = 1;[x,fval] = fgoalattain(fun,x0,goal,weight)
结果为:
1234567
x = 2.0000fval = 3.0000 6.0000
可以看到,目标函数达到了目标值。
例2
目标函数为:
F(x)=[2+∣∣x−p1∣∣25+∣∣x−p2∣∣2/4]\begin{aligned} F(x) = \begin{bmatrix} 2 + ||x-p_1||^2 \\ 5 + ||x-p_2||^2/4 \end{bmatrix} \end{aligned}F(x)=[2+∣∣x−p1∣∣25+∣∣x−p2∣∣2/4]
此处,p1=[2,3]p_1 = [2,3]p1=[2,3] 且p2=[4,1]p_2 = [4,1]p2=[4,1]。目标是 [3,6],权重是 [1,1],线性约束是x1+x2≤4x_1+x_2 \leq 4x1+x2≤4 。
从 x0 = [1,1] 开始求解目标达到问题。
1234567891011
p_1 = [2,3];p_2 = [4,1];fun = @(x)[2 + norm(x-p_1)^2;5 + norm(x-p_2)^2/4];goal = [3,6];weight = [1,1];A = [1,1];b = 4;x0 = [1,1];[x,fval] = fgoalattain(fun,x0,goal,weight,A,b)
123456
x = 2.0694 1.9306fval = 3.1484 6.1484