Steepest descent with exact line search method

54 views (last 30 days)
Abdul Rahim Shihabuddin on 15 Sep 2021
Edited: Matt J on 15 Sep 2021
Noob here . I have been trying to implement steepest descent algorithm on matlab and I first solved it using constant step size. But now I have been trying to implement exact line search method to find the step size which I can't seem to solve . Here's the code I'm working with:
syms x1 x2
syms alpha %stepsize
n=input("Enter the roll number:");
f1=(x1-n)^2 + (x2-2*n)^2;
fx=inline(f1);
fobj=@(x)fx(x(:,1),x(:,2));
%Initial Parameters
x0=[1 1];
k=0;
X=[];
X=[X;x0];
x0=X_new;
k=k+1;
end
fprintf("Optimal solution x=%f,%f\n",x0);
fprintf("Optimal value f(x)= %d \n",fobj(x0));
function y = func(x,b,d,n)
f=@(a)(x+b.*d' -n).^2 + (x+b.*d'-2.*n).^2;
res=fminunc(inline(f),[1,1])
y=res.b
Matt J on 15 Sep 2021
I have reformatted your code and put it in a code well: Matt J on 15 Sep 2021
Edited: Matt J on 15 Sep 2021
n=input("Enter the roll number:");
fobj=@(x) (x(1)-n)^2 + (x(2)-2*n)^2;
x0=[1 1];
k=0;
X=[];
X=[X;x0];
fline=@(a) fobj(x0+a*linedir);
a=fminsearch(fline,0);
x0=x0 + a*linedir;
k=k+1
end
fprintf("Optimal solution x=%f,%f\n",x0);
fprintf("Optimal value f(x)= %d \n",fobj(x0));