am trying to write a matlab program to solve dogleg method for trust region problem, but the program is not working properly. Below is the program. Please i really need your help and suggestions. Thanks

4 次查看(过去 30 天)
clear all
fprintf(' k f0 X(1,1) X(2,1) r b\n')
syms x1 x2
X = [x1 ; x2];
f = (x2 - 0.129*x1^2 + 1.6*x1 - 6)^2 + 6.07*cos(x1) + 10;
w = jacobian(f,X);
g1 = w';
h1 = jacobian(jacobian(f,X));
k = 0;
datasave = [];
x1 = 6; x2 = 14;
g = eval(g1);
h = eval(h1);
b = norm(g); %where b is tol
while k<15
if (eig(h))>0
H = h;
else
lambda = 0.01;
V=abs(min(eig(h)));
H = h + (V+lambda)*eye(size(h));
end
Y = inv(H);
r = (g'*g)/(g'*H*g);
pU = -r*g;
pB = -Y*g;
if 0<=r<=1
P = r*pU;
elseif 1<=r<=2
P = pU + (r-1)*(pB-pU);
end
PP = norm(P);
f = @(x1,x2) (x2-0.129*x1^2+1.6*x1-6)^2+6.07*cos(x1)+10; f0 = f(x1,x2);
X = [x1;x2];
W = g'*P;
Z = 0.5*(P'*H*P);
y = f0+W+Z;
v = f0;
A = X+P;
x1 = A(1,1);
x2 = A(2,1);
q = f(x1,x2);
Q = 0.2; R = 0.25; S = 0.75; I = 2.0; M = 5.0; B = 0.25; C = 2.0;
e = (f0 - q)/(v - y);
if e<R
Inew = B*I;
elseif e>S && PP==I
Inew = min(C*I,M);
else
Inew = I;
end
if e>Q
Xnew = A;
else
Xnew = X;
end
datasave=[datasave; k f0 X(1,1) X(2,1) r b];
Xnew = subs(Xnew);
k = k+1;
X = Xnew;
x1 = X(1,1);
x2 = X(2,1);
gnew = eval(g1);
b = norm(gnew);
hnew = eval(h1);
I = Inew; g = gnew;h=hnew;
end
disp(datasave)

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by