请高手帮我看一下我的matlab程序错在哪里了?min (1000-x(1)^2-2*x(2)^2-

发布时间:2021-02-26 01:52:53

请高手帮我看一下我的matlab程序错在哪里了?min (1000-x(1)^2-2*x(2)^2-x(3)^2-x(1)*x(2)-x(1)*x(3))约束为x(1)^2+x(2)^2+x(3)^2-25=08*x(1)+14*x(2)+7*x(3)-56=0=0程序如下先在MATLAB编辑器中建立非线性约束函数文件:function y=opt

网友回答

1 新建m文件把function y=opt_funl(x)贴进去保存;
2 新建m文件把
function [c,ceq]=opt_conl(x)
ceq=[x(1)*x(1)+x(2)*x(2)+x(3)*x(3)-25];%%去掉第二个式子,那是线性的,不是非线性的
c=[];贴进去保存,ceq是非线性等式约束,楼主的第二个式子是线性的.
3 在mand window里输入
>> options=optimset('LargeScale','off','Display','iter','TolFun',1e-30,'TolX',1e-15,'TolCon',1e-20);
x0=[1;1;1];lb=[0;0;0];Aeq=[8 14 7];Beq=[56];%%线性等式约束用Aeq和beq
[x,f_opt,c,d]=fmincon('opt_funl',x0,[],[],[8 14 7],[56],[0;0;0],[],'opt_conl',options)
max Directional First-order
Iter F-count f(x) constraint Step-size derivative optimality Procedure
0 4 994 27 Infeasible start point
1 10 955.336 22.9 0.25 -295 18.3 infeasible
2 14 964.012 5.773 1 0.811 6.26 Hessian modified
3 18 967.157 0.5242 1 2.83 4.27 Hessian modified
4 22 965.898 0.2011 1 -1.38 3.67
5 26 957.178 3.886 1 -11 0.251
6 30 961.697 0.2039 1 4.24 1.59
7 34 961.564 0.1416 1 -0.196 1.63
8 38 961.679 0.02987 1 0.1 0.0113
9 42 961.715 1.734e-005 1 0.0365 0.002
10 46 961.715 9.332e-011 1 2.12e-005 0.000116 Hessian modified twice
11 50 961.715 2.56e-009 1 -5.53e-009 3.51e-005 Hessian modified
12 54 961.715 6.622e-011 1 2.95e-009 2.67e-006 Hessian modified
13 58 961.715 5.947e-012 1 7.25e-011 7.69e-006 Hessian modified
14 62 961.715 1.357e-012 1 1.4e-012 3.45e-006 Hessian modified
15 72 961.715 1.386e-012 0.0156 1.3e-011 2.55e-005 Hessian modified
16 76 961.715 3.553e-015 1 1.84e-012 3.54e-006 Hessian modified
17 81 961.715 0 0.5 -1.55e-014 6.49e-007 Hessian modified 18 85 961.715 7.105e-015 1 -5.16e-015 8e-006 Hessian modified 19 89 961.715 0 1 7.06e-015 8.32e-006 Hessian modified twice 20 93 961.715 0 1 8.83e-019 6.51e-006 Hessian modified twice 21 97 961.715 0 1 -6.05e-028 1
以上问题属网友观点,不代表本站立场,仅供参考!