Something is wrong in my line search gradient descent code. It gets stuck!
이전 댓글 표시
x0=[10 5]';
x0=[10 5]';
tol=1e-6;
syms x y
f= (1/2)*(x^2)+(9/2)*(y^2);
g=gradient(f, [x, y]);
g0=subs(g, x, x0(1,1));
g0=subs(g, y, x0(2,1));
while norm(g0)>tol
s0=-g0;
%perform a linesearch to find an acceptable step size
alpha=1/2;
L0=1;
f0=subs(f,x, x0(1,1));
f0=subs(f0,y,x0(2,1));
v=f0;
xnew=x0+L0*s0;
f1=subs(f,x, xnew(1,1));
f1=subs(f,y,xnew(2,1));
u=f1;
w=alpha*L0*g0'*s0;
while u > v+w
L0=L0/2;
end
L0;
x0=x0+L0*s0;
end
double(x0)
When I try to run the script it gets stuck I guess, it returns the output
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!