I am trying to bracket the roots of a function with the variable p. The assumptions are: the root exist between 0 and 1, the value of the function is positive at p = 0.
The code That I have written is as follows:
bracketRoot[funL_] :=
Module[{i, p, dp = 0.1, Nfun},
For[i = 0, i <= 1, i = i + dp,
Nfun = funL /. p -> i;
If[Im[Nfun] == 0,
If[Nfun < 0, Print[Nfun]; Return[{i - dp, i}];];,
Print["encountered a complex value for the function before bracketing the root!"];
Print["Returning the p value for which the function is real..."];
Return[{i - 2 dp, i - dp}];];];
Print["Could not bracket the root ...."];
Return[{0, 1}];];
When the function is called in my notebook, I am able to get the proper answer. But If I call this function from another function, the function is returning {0, 1} with a print message.
It appears that the replacement rules are not effective in the module for p. This problem appears similar to Q1. But I could not understand.
A similar question is asked Q2. I tried this solution also. But this also could not solve the problem.
Kindly throw some light on the problem by analyzing it.
Edit:
My functions are complicated in p. The function is tested with a simple expressions like:
from a note book:
bracketRoot[(p-1)(p-4.5)]
declaring p as local variable in bracketRoot, the function is called from a module (a sample code):
fun1[]:=Module[{initset},
initset=bracketRoot[(p-1)(p-4.5)];
Print[initset]; (*to know output*)
];
fun1[]
@m_goldberg answer is helpful for the problem. Thank you.

