You are on page 1of 1

function [x,n,N] = SteepestDescent(f,g,x0,nmax,tol,lstol)

% Checking input arguments and assigning default values.


narginchk(6,6)
if ~isequal(class(f),class(g),'function_handle')
error('LineSearch: f must be a function handle')
end
if ~isvector(x0)
error('LineSearch: x0 must be a vector')
end
if isequal(nmax,[])
nmax = 100;
end
if isequal(tol,[])
tol = 1e-2;
end
if isequal(lstol,[])
lstol = 1e-3;
end

n = 0;
N = 0;
x = x0;
xold = 2*x + 1e9;

while max(abs(x - xold)) > tol && n <= nmax


xold = x;
d = -g(xold);
f_tilte = @(a) f(xold + a*d);
[a,nls] = LineSearch(f_tilte,1e-3,100,lstol);
N = N + nls + length(d);
x = xold + a*d;
n = n + 1;
end

end

Error using SteepestDescent (line 4)


Not enough input arguments.

Published with MATLAB® R2021a

You might also like