# Difficulty implementing logarithmic barrier in Matlab.

I'm trying to create a convex optimization code in Matlab , to deal with inequality constraints I'm using logarithmic barrier.Suppose we have inequality $g(x) =< 0$ to satisfy,so I define $\varphi (x) = -log(-g(x))$,What if in an iteration $g(x)$ becomes positive? as $\varphi$ is not defined when $g(x) > 0$ ,the algorithm stuck in that $x$,I tried the code segment bellow but sometimes it cause the code to stuck in this" while" for ever:(beta is line search parameter)

while (g(x+ s*delta) > 0),
s = BETA*s;
end % first get feasible point ... then search minimum


Do you have any idea how to deal with this?

• If $g(x)\geq 0$ then there is definitely no way to exit that loop. So the point is that $g(x)$ itself must always be negative. Your code has to explicitly ensure that is the case before you even get here. Unfortunately we don't have context here. – Michael Grant Mar 23 '18 at 14:06
• @MichaelGrant So you mean defining logarithmic barrier is not enough to force $g(x)$ remain negative,and I have to take care of this before I even define logarithmic barrier am I right?If that's not the point can you give me some more hints? – MAh2014 Mar 23 '18 at 14:59
• That's correct. You still have to take explicit steps in your code to make sure that $g(x)$ stays positive. – Michael Grant Mar 23 '18 at 15:00
• @MichaelGrant Thank you so much for your hint. – MAh2014 Mar 23 '18 at 15:25