-3
$\begingroup$
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(g0, 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 this script in Matlab. It gets stuck. I don't know why! is there something wrong with the code?

$\endgroup$

closed as off-topic by Brian Borchers, Bill Greene, Kirill, Anton Menshov, sssssssssssss Dec 30 '18 at 16:54

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

1
$\begingroup$

The while loop only changes L0, but u, v and w stay the same. So the condition for the loop never changes.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.