Matlab fgoalattain及其原因';It’这个简单的功能不行

Matlab fgoalattain及其原因';It’这个简单的功能不行,matlab,optimization,Matlab,Optimization,我正在考虑使用fgoalattain来帮助我根据目标分布生成破碎岩石的碎片。在设置此函数之前,我认为在x^2上测试它是明智的 这是密码 fun = @(x) x^2; goal = [16]; weight = [1]; x0 = 0; [x,fval,attainfactor,exitflag,output] = fgoalattain(fun,x0,goal,weight) 我希望答案是4 matlab R2017b将返回以下内容 Local minimum possible.

我正在考虑使用fgoalattain来帮助我根据目标分布生成破碎岩石的碎片。在设置此函数之前,我认为在x^2上测试它是明智的

这是密码

 fun = @(x) x^2;
 goal = [16];
 weight = [1];
 x0 = 0;
 [x,fval,attainfactor,exitflag,output] = fgoalattain(fun,x0,goal,weight)
我希望答案是4

matlab R2017b将返回以下内容


Local minimum possible. Constraints satisfied.

fgoalattain stopped because the size of the current search direction is less than
twice the default value of the step size tolerance and constraints are 
satisfied to within the default value of the constraint tolerance.

<stopping criteria details>


x =

     0


fval =

     0


attainfactor =

   -16


exitflag =

     4


output = 

  struct with fields:

         iterations: 2
          funcCount: 7
       lssteplength: 1
           stepsize: 0
          algorithm: 'active-set'
      firstorderopt: []
    constrviolation: 0
            message: 'Local minimum possible. Constraints satisfied.↵↵fgoalattain stopped because the size of the current search direction is less than↵twice the default value of the step size tolerance and constraints are ↵satisfied to within the default value of the constraint tolerance.↵↵Stopping criteria details:↵↵Optimization stopped because the norm of the current search direction, 0.000000e+00,↵is less than 2*options.StepTolerance = 1.000000e-06, and the maximum constraint ↵violation, 0.000000e+00, is less than options.ConstraintTolerance = 1.000000e-06.↵↵Optimization Metric                                              Options↵norm(search direction) =   0.00e+00                        StepTolerance =   1e-06 (default)↵max(constraint violation)  =   0.00e+00              ConstraintTolerance =   1e-06 (default)'

可能的局部最小值。满足约束条件。
fgoalattain已停止,因为当前搜索方向的大小小于
步长公差和约束的默认值是默认值的两倍
满足约束公差的默认值。
x=
0
fval=
0
获得因子=
-16
出口滞后=
4.
输出=
带字段的结构:
迭代次数:2次
总数:7
lssteplength:1
步长:0
算法:“活动集”
firstorderopt:[]
违反:0
信息:'本地最小可能值。满足约束条件。↵↵fgoalattain已停止,因为当前搜索方向的大小小于↵步长公差和约束的默认值是默认值的两倍↵满足约束公差的默认值。↵↵停止准则详情:↵↵优化停止,因为当前搜索方向的范数为0.000000e+00,↵小于2*options.StepTolerance=1.000000e-06,且为最大约束↵违规0.000000e+00小于options。ConstraintTolerance=1.000000e-06。↵↵优化度量选项↵标准(搜索方向)=0.00e+00步距公差=1e-06(默认值)↵最大值(违反约束)=0.00e+00约束公差=1e-06(默认值)'
这显然是错误的,我不知道为什么。请帮忙。

这意味着目标已经超额完成。如果希望准确实现目标,请使用以下选项:

o = optimoptions('fgoalattain','EqualityGoalCount',1);
[x,fval,attainfactor,exitflag,output] = fgoalattain(fun,x0,goal,weight,[],[],[],[],[],[],[],o)
还需要一个改变。fgoalattain算法使用梯度来查找搜索方向。它不能从0的起点移动,因为它的梯度为0;0是函数x^2的最小值。如果你设置了一个非零的初始点,比如说1,那么这个目标就是在x=4的情况下实现的

Local minimum possible. Constraints satisfied.

fgoalattain stopped because the size of the current search direction is less than
twice the value of the step size tolerance and constraints are 
satisfied to within the value of the constraint tolerance.

<stopping criteria details>

x =

    4.0000


fval =

   16.0000


attainfactor =

  -1.6941e-21


exitflag =

     4
可能的局部最小值。满足约束条件。
fgoalattain已停止,因为当前搜索方向的大小小于
步长公差和约束值的两倍是
满足到约束公差的值范围内。
x=
4
fval=
16
获得因子=
-1.6941e-21
出口滞后=
4.
表示目标已经超额完成。如果希望准确实现目标,请使用以下选项:

o = optimoptions('fgoalattain','EqualityGoalCount',1);
[x,fval,attainfactor,exitflag,output] = fgoalattain(fun,x0,goal,weight,[],[],[],[],[],[],[],o)
还需要一个改变。fgoalattain算法使用梯度来查找搜索方向。它不能从0的起点移动,因为它的梯度为0;0是函数x^2的最小值。如果你设置了一个非零的初始点,比如说1,那么这个目标就是在x=4的情况下实现的

Local minimum possible. Constraints satisfied.

fgoalattain stopped because the size of the current search direction is less than
twice the value of the step size tolerance and constraints are 
satisfied to within the value of the constraint tolerance.

<stopping criteria details>

x =

    4.0000


fval =

   16.0000


attainfactor =

  -1.6941e-21


exitflag =

     4
可能的局部最小值。满足约束条件。
fgoalattain已停止,因为当前搜索方向的大小小于
步长公差和约束值的两倍是
满足到约束公差的值范围内。
x=
4
fval=
16
获得因子=
-1.6941e-21
出口滞后=
4.