Perhaps this question has a simple answer, I'm sorry but I unable to get my head around it. Here's a minimal description of my issue.
I have a an equation of the form eq = expr == 0
, where expr
is a very complicated function of the symbols x
and y
.
I wish to find the roots of the equation for various values of y
. Thus I defined the function:
f = Function[z, {z, x /. FindRoot[eq /. y -> z, {x, 0}]}]
I then define a grid:
grid = Range[ymin, ymax]
and map over it:
res = Map[f, grid]
Apparently my equation is quite hard to solve as I get:
After playing with it changes to the options of FindRoot
such as: adding more iterations, change of method, changing working precision, etc., doesn't help me.
Thus what I would like is to be able to figure out how bad am I doing. My issues are:
- I don't know how many times did the execution occur as after a certain amount of times it suppresses the alerts
- I don't know if the issues are within a certain domain, in which case I'll know I have a domain where I can't solve my equation. On the other hand maybe the points where I have my issues are sparse in which case maybe I may just ignore them?
In short I would like to add to my code (or have a separate code running over the same grid) some sort of error handler which would do one of two things:
- Count exceptions and give me a tally. Preferably it should also defer between different exceptions as
FindRoot
can throw other exceptions as well. - An even better option is to return a array of exceptions and grid values, in the form:
{{excep1, GridVal1},{excep2, GridVal2},{excep3, GridVal3},{excep4,GridVal4}}
I didn't post any attempt as I don't even know how to start. Complete solutions, as weak as general directions will be most welcome.
Update
I still haven't solved my issue. However I gained some intuition regarding my problem. The solution my equation is discontinuous. In a region around the discontinuity I have big oscillations. I could in principle be satisfied with with a solution only within a bounded domain. However, my actual problem involves several equations with several variables, so I'll need this sort of error handler to define the feasible domain.
eq = expr == 0
giveseq
a boolean value, i.e.True
orFalse
. Mathematica can't find a root of that. Replaceeq
withexpr
inside yourFindRoot
and that may solve the issue. $\endgroup$ – Myridium Mar 2 '17 at 13:22expr==0
remains unevaluated. $\endgroup$ – Myridium Mar 2 '17 at 14:25