Something is wrong in my line search gradient descent code. It gets stuck!
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!