Matlab fmincon-未找到可行的解决方案,但未发现错误

Matlab fmincon-未找到可行的解决方案,但未发现错误,matlab,optimization,error-handling,Matlab,Optimization,Error Handling,我正在使用优化函数“fmincon”,在某些情况下它不会收敛。我必须识别这些情况并采取必要的措施,但使用的所有方法都无法捕获错误,因此我继续获取错误: No feasible solution found. fmincon stopped because the size of the current search direction is less than twice the default value of the step size tolerance but constraints

我正在使用优化函数“fmincon”,在某些情况下它不会收敛。我必须识别这些情况并采取必要的措施,但使用的所有方法都无法捕获错误,因此我继续获取错误:

No feasible solution found.

fmincon stopped because the size of the current search direction is less than
twice the default value of the step size tolerance but constraints are not 
satisfied to within the selected value of the constraint tolerance.
首先,我尝试选择函数的exitflag:如果它返回一个已知错误(-1,1,0…),但每次出现错误时,返回的exitflag都有一个正确的值

[x,fval,exitflag] = fmincon(@(x) costFunction(x,INPUTS),x0,A,b,[],[],lb,ub,[],options);
if exitflag == 0
    do something;
end
然后我尝试使用“try/catch”结构,但在本例中,代码继续运行,没有出现错误

try %start try/catch
    [x,fval,exitflag] = fmincon(@(x) costFunction(x,INPUTS),x0,A,b,[],[],lb,ub,[],options);
catch err
   disp(err.identifier);
       ... actions 
end  % end try/catch
欢迎提出任何建议

注:使用的选项有:

options = optimset(oldopts,'Display','notify', 'Algorithm','active-set', 'MaxFunEvals', 10000);
  • 旧选项中的内容是什么
  • 小于步长公差默认值的两倍
    建议您需要更改步长或公差值。有几种方法可以实现这一点:猜测或显示迭代显示

    optimset(oldopts,'Display','iter' ...% or 'iter-detailed'
    
  • 确定要更改的内容后,可以将其设置为:

    optimset(options,'stepsize', 1e-2) % or optimset(options,'tolX', 1e-e)...
    
  • 停止查看退出标志以抛出错误。误差是一个收敛或迭代问题

  • 问问自己,如果可能的话,算法是否能够使用图形方法收敛

  • RTM:

  • 根据本文,您应该注意
    exitFlag==-2
    而不是
    0
    来检查该场景:

    i、 e


    您是否提供了一个满足约束的
    x0
    ?我检查了,实际上在某些情况下,x0不满足约束,我也会更新这个。好的,这也是一个选项,我会尝试,但它仍然会捕获错误,不会像什么都不传递。。。
    [x,fval,exitflag] = fmincon(@(x) costFunction(x,INPUTS),x0,A,b,[],[],lb,ub,[],options);
    if exitflag == -2
        %// Handle non-convergence
    else
        %// Converged
    end