Steepest descent method algorithm

조회 수: 10 (최근 30일)
Luqman Saleem
Luqman Saleem 2019년 9월 17일
댓글: Saleh Msaddi 2020년 3월 9일
For practice purpose, I want to find minima of -humps() function.
I have written the following code but it's not giving correct answer
clear; clc;
%function
f = @(x) -humps(x);
dx = 0.1; %step length
x_current = 1; %starting guess
delta = 1e-4; %threshold value
alpha = 0.1; %finding optimal step length
g = inf; %starting gradient
while norm(g) > delta
%gradient by finite difference
f1 = f(x_current + dx/2);
f2 = f(x_current - dx/2);
g = (f1-f2)/dx;
x_next = x_current-alpha*g; %new solution
x_current = x_next;
fprintf('%d %d\n',x_current,x_next);
x_current = x_next;
end
It give 5.543798e+01 as solution while the solution should either be 0.9 or 0.3 (local and global minimas, respectivily).
Whate am I missing here? can anyone help?

채택된 답변

Matt J
Matt J 2019년 9월 17일
alpha is too big. Try alpha=0.001.
  댓글 수: 2
Luqman Saleem
Luqman Saleem 2019년 9월 17일
편집: Luqman Saleem 2019년 9월 17일
@Matt J It worked. I am so stupid.
With initial guess = 0, the solution converges to 0.3 (global minima) while with guess=1, the solution is 0.9 (local minima).
Do you know any way to bypass local minima and get to global minima always? I am trying to understand multiscaling, can you help me understanding this.
Thank you very much.
Saleh Msaddi
Saleh Msaddi 2020년 3월 9일
In steepest descent, you would always get the local minima. You'd only get the global minima if you start with an initial point that would converge to the global minima; if you're lucky enough. If your stepping size is too small, your solution may converge too slow or might not converge to a local/global minima. On the contradictory, if you choose a big step size, your solution may miss the minimal point.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by