我想用matlab梯度法求解目标函数用matlab梯度法求解二维无约束目标函数f(x)=x1^2+x2^2-x1x2-10x1-4x2+60的极小值,初始点x(上标0)=【0,0】的转制,迭代精度 t=0.001
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/23 22:48:06
我想用matlab梯度法求解目标函数用matlab梯度法求解二维无约束目标函数f(x)=x1^2+x2^2-x1x2-10x1-4x2+60的极小值,初始点x(上标0)=【0,0】的转制,迭代精度 t=0.001
我想用matlab梯度法求解目标函数
用matlab梯度法求解二维无约束目标函数f(x)=x1^2+x2^2-x1x2-10x1-4x2+60的极小值,初始点x(上标0)=【0,0】的转制,迭代精度 t=0.001
我想用matlab梯度法求解目标函数用matlab梯度法求解二维无约束目标函数f(x)=x1^2+x2^2-x1x2-10x1-4x2+60的极小值,初始点x(上标0)=【0,0】的转制,迭代精度 t=0.001
(i)编写M文件detaf.m如下
function [f,df]=detaf(x);
f=x(1)^2+x(2)^2-x(1)*x(2)-10*x(1)-4*x(2)+60;
df(1)=2*x(1)-x(2)-10;
df(2)=2*x(2)-x(1)-4;
(ii)编写M文件tidu.m
clc
x=[2;2];
[f0,g]=detaf(x);
while norm(g)>0.001
p=-g'/norm(g);
t=1.0;f=detaf(x+t*p);
while f>f0
t=t/2;f=detaf(x+t*p);
end
x=x+t*p
[f0,g]=detaf(x)
end
在命令窗口运行tidu,回车
x =
0.9285
0.3714
f0 =
49.8848
g =
-8.5144 -4.1857
x =
1.8259
0.8126
f0 =
41.0013
g =
-7.1608 -4.2008
x =
2.6884
1.3186
f0 =
33.2628
g =
-5.9417 -4.0513
x =
3.5147
1.8819
f0 =
26.6059
g =
-4.8526 -3.7508
x =
4.3059
2.4935
f0 =
20.9888
g =
-3.8818 -3.3189
x =
5.0659
3.1433
f0 =
16.3877
g =
-3.0115 -2.7793
x =
5.8008
3.8215
f0 =
12.7914
g =
-2.2200 -2.1577
x =
6.5179
4.5185
f0 =
10.1958
g =
-1.4828 -1.4808
x =
7.2254
5.2252
f0 =
8.6002
g =
-0.7743 -0.7751
x =
7.9322
5.9326
f0 =
8.0046
g =
-0.0683 -0.0669
x =
8.0215
6.0201
f0 =
8.0004
g =
0.0229 0.0187
x =
7.9973
6.0003
f0 =
8.0000
g =
-0.0058 0.0034
x =
8.0006
5.9984
f0 =
8.0000
g =
0.0029 -0.0039
x =
7.9995
5.9999
f0 =
8.0000
g =
1.0e-003 *
-0.9686 0.3678
x =
7.9999
5.9997
f0 =
8.0000
g =
1.0e-003 *
0.1177 -0.4353
最优结果为:
x =
7.9999
5.9997
f0 =
8.0000
g =
1.0e-003 *
0.1177 -0.4353