# How to resolve the fminunc problem

3 views (last 30 days)
Houda on 5 Jul 2017
Commented: Houda on 6 Jul 2017
Hey everybody, I am runing the post maximization of a financial friction model but each time I run it I have the following errors:
Error in ==> post_minus at 3
x = trans2(xtrans);
??? Error using ==> feval
Output argument "min_post" (and maybe others) not assigned during call to "F:\new
folders\67bis\Restricted Models (Table 3)\Fin Frictions Mod\Post
Maximization\post_minus.m>post_minus".
Error in ==> lineSearch>bracketingPhase at 103
f_alpha =
feval(funfcn{3},reshape(xInitial(:)+alpha*dir(:),sizes.xRows,sizes.xCols),varargin{:});
Error in ==> lineSearch at 48
Error in ==> fminusub at 208
Error in ==> fminunc at 367
Error in ==> max_run_loop at 72
When I run this code with the original data of the author it works and even with another set of variable, but using this data I didn't succeed to obtain the posterior mode and the inverse of the Hessian matrix to finish the estimation procedure (the original code can be found in the homepage of Andrés Fernandez).
Houda
Walter Roberson on 5 Jul 2017
Could you clarify which routine you are calling, and with what parameters?

Walter Roberson on 5 Jul 2017
The code in post_minus includes the line
if logprior(1) == NaN
It is not possible to use "==" to compare to NaN . NaN == NaN is false. NaN has the strange property of being the only value for which x ~= x . The test should be
if isnan(logprior(1))
and likewise further down for elseif logdata(1) == NaN
Further down the code has
if ind == 1 % ind. is a flag signaling the inexistence of solution
return;
end
It does this without having assigned a value to min_post. It should probably be
if ind == 1 % ind. is a flag signaling the inexistence of solution
min_post = 0;
return;
end
This is probably what you are encountering, that it is detecting that there is no feasible solution.
Houda on 6 Jul 2017
Dear Walter, it works you saved me, many thannnnnnnnnnnnnnnnks