Help using fmincon function
1 次查看(过去 30 天)
显示 更早的评论
I attached a picture of the problem I'm working on.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/146806/image.png)
objecfun is:
function f = objecfun(x)
f = (x(1)-x(2))^2 + (x(2)+x(3)-2)^2 + (x(4)-1)^2 + (x(5)-1)^2;
end
optscript is:
x0 = [2;2;2;2;2];
A = [ ];
b = [ ];
Aeq = [1 3 0 0 0; 0 0 1 1 -2; 0 1 0 0 -1];
beq = [0;0;0];
lb = [-10;-10;-10;-10;-10];
ub = [10;10;10;10;10];
[x,fval] = fmincon('objecfun',x0,A,b,Aeq,beq,lb,ub);
When I run optscript, I keep getting this error:
>> optscript
Warning: The default trust-region-reflective algorithm does not solve problems
with the constraints you have specified. FMINCON will use the active-set
algorithm instead. For information on applicable algorithms, see Choosing the
Algorithm in the documentation.
> In fmincon at 501
In optscript at 8
Warning: Your current settings will run a different algorithm (interior-point)
in a future release.
> In fmincon at 506
In optscript at 8
Local minimum possible. Constraints satisfied.
fmincon stopped because the predicted change in the objective function
is less than the default value of the function tolerance and constraints
are satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
No active inequalities.
0 个评论
回答(1 个)
Matt J
2015-1-14
It's not an error. It's a warning. There's no evidence of anything wrong. However, your problem is more appropriate to LSQLIN than to FMINCON, so you might consider using that instead.
2 个评论
Matt J
2015-1-14
Try this instead
[x,fval] = fmincon(@objecfun,x0,A,b,Aeq,beq,lb,ub);
When I run it this way, I get
x =
-0.7674
0.2558
0.6279
-0.1163
0.2558
fval =
4.0930
which is also what LSQLIN gives me.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Least Squares 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!