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
g = .5*(y/exp(xxx + a*b)-1) -(xxx-d*(1-a))/c;
H1= -0.5*y/exp(xxx + a*b)-1/c;
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:
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?