Different optimization methods not working when I change derivative discretization.

2 vues (au cours des 30 derniers jours)
I have no problem trying to find the minimum for the following function:
f = fun(X)
f = 0;
for i = 2:N;
f = f + 0.5*(X(i) + X(i-1))*sqrt(1 + ( ( X(i) - X(i-1) ) / h )^2)*h;
end
where F is a function of z, F(i) is the value for F at z(i) and h is constant and equivalent to z(i) - z(i-1) (I provided a simplified version of the function).
The derivative discretization of X is represented by ( X(i) - X(i-1) ) / h, and X(1) = X(N) = 1
The problem arises when I try to implement a different discretization method for the derivative, as using the central difference, where the for loop would be:
for i = 1:N-1;
if i == 1
f = f + 0.5*( X(i) + X(i+1) )*sqrt( 1 + ( ( -3*F(i) + 4*F(i+1) - F(i+2) ) / (2*h) )^2 )*h;
else
f = f + 0.5*(X(i) + X(i+1))*sqrt( 1 + ( ( X(i+1) - X(i-1) ) / ( 2*h ) )^2 )*h;
end
end
I have tried to use several optimization tools, such as fminunc, fmincon, fminsearch and others, and the solution always seems to diverge to minus infinity. However, if I try to optimize the first function and plug the solution into the second one, I get relatively close results, 0.9537 and 0.9538 respectively, which I know to be correct.
I have also tried changing the initial values, function and x tolerance, lower bounds and such.
My question is why does this second function diverege when used by itself to optimize, and whether there is a way around it.
Thanks in advance.

Réponses (1)

Alan Weiss
Alan Weiss le 10 Avr 2019
I do not understand why you are creating approximate derivatives yourself. fmincon and the other optimization functions perform their own internal finite difference approximations by default. You can control whether they use central or forward finite differences using the FiniteDifferenceType option (for fmincon and fminunc; the fminsearch solver does not use approximate derivatives). See the function reference pages for how to use options.
Alan Weiss
MATLAB mathematical toolbox documentation

Catégories

En savoir plus sur Nonlinear Optimization dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by