Newton method to optimize function, error
1 次查看(过去 30 天)
显示 更早的评论
Hey guys,
im trying to use the newton method for optimizing my following function. I also used the Grid-search method, this worked totaly fine.
Now here is my try with the Newton method:
Imax=100; % Anzahl an maximalen Iterationen
tol=1;
i=1; % Zähler der Schleife
f=[diff(logL,b);diff(logL,y);diff(logL,A);diff(logL,B)]; % Partielle Ableitungen von logL
J=[diff(f,b) diff(f,y) diff(f,A) diff(f,B)]; % Aufstellen der Jacobi-Matrix
X=zeros(Imax,length(J)); % Matrix erstellen
X(1,:)= [27 3 0.04 0.3]; % Startwerte für 1.Iteration
while tol>=1e-9 % Toleranz
% Einsetzen der Werte für Startwertvariablen in Gleichung
fvar=subs(f,{'b' 'y' 'A' 'B'},{X(i,1) X(i,2) X(i,3) X(i,4)});
f_var=subs(J,{'b' 'y' 'A' 'B'},{X(i,1) X(i,2) X(i,3) X(i,4)});
% Evaluieren für Werte für Startwertvariablen
fvalue=eval(fvar);
f_value=eval(f_var);
if max(max(isnan(f_value))) == 1
break
end
% Neuer X Lösungsvektor
*| |*X(i+1,:)=([X(i,1) X(i,2) X(i,3) X(i,4)]'-f_value\fvalue)';*||*
% Abweichung zwischen neuen und alten Werten
tol=abs([X(i,1) X(i,2) X(i,3) X(i,4)] - [X(i+1,1) X(i+1,2) X(i+1,3) X(i+1,4)]);
if i>Imax % Abbruchkriterium
break
end
i=i+1;
end
fprintf('Endergebnis : '); % Endergebnis
[X(i,1) X(i,2) X(i,3) X(i,4)]
Im getting the error message:
> In zwei_parametrig_ohneAB_NEWTON_VERFAHREN (line 54)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.698726e-31.
> In zwei_parametrig_ohneAB_NEWTON_VERFAHREN (line 54)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 7.517962e-30.
> In zwei_parametrig_ohneAB_NEWTON_VERFAHREN (line 54)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.202871e-28.
> In zwei_parametrig_ohneAB_NEWTON_VERFAHREN (line 54)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.924598e-27.
> In zwei_parametrig_ohneAB_NEWTON_VERFAHREN (line 54)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.079253e-26.
> In zwei_parametrig_ohneAB_NEWTON_VERFAHREN (line 54)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.926967e-25.
And after that, MATLAB gives me "wrong" solutions:
-0.0000 -102.4938 108.4393 -217.2624
By googling the error message i know, that there must be something wrong with my matrix i have marked in the code below. Where is the problem?
Your sincerly, Ronald Singer
1 个评论
采纳的回答
Matt J
2017-8-3
编辑:Matt J
2017-8-3
It would help to know what logL looks like.
The message means that your Hessian matrices f_value are close to singular and therefore difficult to invert. You should examine them when the warning is triggered,
>> dbstop if warning
Possibly, you have landed in a region where logL is approximately flat everywhere making the Hessian approximately equal to zero(4). I also notice that you are not doing any line search steps. For non-quadratic function minimization, line searches are needed to assure convergence of Newton's method.
10 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!