# How to find function existence border

I have a function like this

f[x_, a_] = Log[-x - a]*(-x - a) + Sin[a];


this function does exist if x > a because of Log[]. a - parameters. if I plot a few graphs with different a like this

Plot[{f[x, 1], f[x, 1.4], f[x, 1.8], f[x, 2]}, {x, -4, 4}]


I get a graph like this

My Question: Can I get somehow a function of the last existing point of the f[], like FLast[x] like I marked in the graph by black dots? Of course I understand that function f[] exists everywhere, but becomes complex at point x=a and if I will plot Re[f[...]] it will plot graph everywhere.

In other words I need to find a border, where my function becomes complex.

This is an artificial example and most probably it is possible to find analitycal solution for this function f[], but my real function is numeric solution of differential equation which is very complicated and cannot be found analitically.

• For your simple example, you can use FunctionDomain[]. For your actual problem (based on your sketch), you can probably use WhenEvent[]. – J. M.'s ennui Mar 14 '16 at 22:53
• Will FunctionDomain work for complicated numerical function? – Zlelik Mar 15 '16 at 11:35
• Likely, no. Since you didn't post your DE, I only gave a hint on using event detection for your purpose. – J. M.'s ennui Mar 15 '16 at 11:39

Here's a way that goes into the innards of the Plot, extracts the lines, finds the last points, and adds them to the plot:

f[x_, a_] = Log[-x - a]*(-x - a) + Sin[a];
Show[
#,
Epilog -> {PointSize[0.02], Black, Point@*Last /@ Cases[Normal@#, Line[a_] :> Sort[a], Infinity]}
] &@ Plot[{f[x, 1], f[x, 1.4], f[x, 1.8], f[x, 2]}, {x, -4, 4}]


• Actually I do not need a points. I need a function like FLast[x] to perform further analysis. Finally I do not need the grapf of f[x,a], I really only need FLast[x]. As I understand I could find it by solving equation Im[f[x,a]]==0+, but even NSolve[Im[f[x,1]]==0.001, x] does not work. – Zlelik Mar 15 '16 at 11:17
• NSolve[f[x,1]==0.001*I, x] works fine, but looks like mathematica works strange with Im[] function. – Zlelik Mar 15 '16 at 11:23
• @Zlelik. I recommend taking J.M.'s advice and posting more details about your code. J.M. is right that probably WhenEvent inside NDSolve is the way to go, but there's no way to help without seeing your code to begin with. Nonetheless, I might try to take J.M.'s suggestion about `FunctionDomain' and post something about it if I find the time. – march Mar 15 '16 at 17:03
• It is really difficult to post code, because it is really huge, I think 10 pages of code and execution time 2 days. I will try to make simplified example with NDSolve. But in General why NSolve[Im[f[x,1]]==0.001, x] does not work? – Zlelik Mar 16 '16 at 18:04