MATLAB Answers

finding the maximun of a function along with hessian matrix

5 views (last 30 days)
ektor on 24 Dec 2017
Edited: Matt J on 24 Dec 2017
Dear All,
I have the following function
f=-1/2*log(2*pi) -.5*(x+a*b) -.5*y./exp((x+a*b) ) -1/2*log(2*pi*c)-0.5*(x-d*(1-a))^2/c;
where a,b,c,d and y are known values.
I want to find the maximun of this function and to evaluate the hessian of this function at the maximun point. So I use the Newton Rapshon method
xxx=x0;% x0 is the initial point
while norm(err)>10^(-6)
g = .5*(y/exp(xxx + a*b)-1) -(xxx-d*(1-a))/c; % gradient
H1= -0.5*y/exp(xxx + a*b)-1/c; % Hessian
xxx=xxx- err;
Then, I obtain the resulting xxx, say xxx* and I evaluate H1 at this xxx*.
The above algorithm is part of a bigger code. However, when I use the fminunc to find the maximun (of the minus f) instead of the Newton rapshon method:
'GradObj','off', 'Hessian','off','DerivativeCheck','off');
y, a, d, c, b);
where 'function' is the minus target fucntion (-f), I observe that my code works a lot better, albeit it is much slower.
Any ideas why there is such a difference and is there a way to use a more efficient Newton Rapshon method which is much faster?


Sign in to comment.

Accepted Answer

Matt J
Matt J on 24 Dec 2017
Edited: Matt J on 24 Dec 2017
Well, for one thing, fminunc's algorithms are not the same as what you've implemented. They have elements in common with Newton-Raphson, but they are not pure Newton-Raphson. Pure Newton-Raphson is not generally that reliable.
Another reason is that you have turned 'GradObj' and 'Hessian' off. Therefore, fminunc has to do extra work to numerically approximate the derivatives.
FInally, the fminunc code is much more general and heavily featured than yours - it runs error checks and supports various user options that your custom code does not.


Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by