请高手帮我看一下我的matlab程序错在哪里了? min (1000-x(1)^2-2*x(2)^2-x(3)^2-x(1)*x(2)-x(1)*x(3))
发布网友
发布时间:2022-05-30 03:59
我来回答
共3个回答
热心网友
时间:2023-10-06 08:31
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 在command 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 Procere
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.33e-006 Hessian modified twice
Optimization terminated: magnitude of search direction less than 2*options.TolX
and maximum constraint violation is less than options.TolCon.
No active inequalities.
x =
3.5121
0.2170
3.5522
f_opt =
961.7152
c =
4
d =
iterations: 21
funcCount: 97
stepsize: 1
algorithm: 'medium-scale: SQP, Quasi-Newton, line-search'
firstorderopt: 1.3292e-006
cgiterations: []
message: [1x142 char]
热心网友
时间:2023-10-06 08:31
建议你去官网看看 或者下载视频教程追问好的,谢谢啊,视频教程没找到,你有吗?能给我发一份吗?谢谢了,我的邮箱为songyuzhu2005@163.com。多谢。
热心网友
时间:2023-10-06 08:32
是不是 opt_fun1 与opt_funl的1与l的区别!