# Function not evaluating as expected [closed]

I'm not sure I understand why this is not working and why it's giving different answers:

A simple example illustrating the issue is below:

U[x_, p_] := RegionMeasure[ImplicitRegion[
(v - p - x >= 0 && 0 <= v <= 1 ) , {v}]]

q[p_] := (x /. FindRoot[x - U[x, p] == 0, {x, 0.5, 0, 1}])

q[.4]

(q[p]) /. {p -> 0.4}


Why are those two evaluations not consistent? I would think that the last line would do the same thing as the line before it, but it gives a different answer.

• Change the definition of q to q[p_?NumericQ] := (x /. FindRoot[x - U[x, p] == 0, {x, 0.5, 0, 1}]) Since the function uses a numeric technique, it needs to be restricted to a numeric argument. Jul 2, 2021 at 18:47
• Ah, thanks! I also want to ask why this doesn't work: Manipulate[ RegionPlot[{ (v - p - x > 0 ) /. {x -> q[p]} }, {v, 0.000000001, 1}, {c, 0.001, 1} (* Just to see it as a 2D RegionPlot *), FrameLabel -> Automatic], {p, .001, 1}] Even after following the suggestion above, there is still an 'Uncaught SystemException' error Jul 2, 2021 at 18:55
• I suggest that you formulate a new question. In your RegionPlot what does c represent? It must relate to the Region to be plotted. Jul 2, 2021 at 19:30
• I just used c to make it into a 2d regionplot. There is no c in the model, so I'm expecting a vertical band of blue across all c for the range of v for which the inequality holds. I'll make another post. Thanks again! Jul 2, 2021 at 20:00
• Keep in mind that the function q will also fail if x has a value. It's better to use Module[{x}, x /. FindRoot[x - U[x, p] == 0, {x, 0.5, 0, 1}]] to make sure that's not going to be an issue. Jul 2, 2021 at 20:49