I have a function Fdiff[m]
that I want to put in FindRoot
. However, it has given me an error saying that the integrand has evaluated to non-numerical values. I'm aware of other posts having this issue as well, but reading those did not lead to a solution in my case.
I have used ?NumericQ
as well as trying to integrate first to get an expression just in terms of m
before putting in FindRoot
, but I think this can't be done since my integrand is a bit complicated so maybe there's no analytic result, so using NIntegrate
is must, but for this to work m
has to have a value. So I checked that Fdiff[m]
for some specific value of m
indeed works.
I believe the syntax of my code is correct but I'm not sure why this problem persist. Any help?
Clear["Global`*"]
a = Rationalize[4.046];
b = Rationalize[0.01613];
c = Rationalize[0.227];
A[z_] := -a Log[b z^2 + 1]
int1[zh_] = ((Integrate[y^3 Exp[-3 A[y]], y] /. {y -> zh}) - (Integrate[y^3 Exp[-3 A[y]], y] /. {y -> 0})) // Simplify;
int2[zh_] = ((Integrate[y^3 Exp[-3 A[y] + c y^2], y] /. {y -> zh}) - (Integrate[y^3 Exp[-3 A[y] + c y^2], y] /. {y -> 0})) // Simplify;
s[zh_] := Exp[3 A[zh]]/(4 zh^3);
T[m_, zh_] := Rationalize[((zh^3 Exp[-3 A[zh]])/(4 Pi int1[zh])) (1 - ((2 c m^2)/(1 - Exp[c zh^2])^2) (Exp[c zh^2] int1[zh] - int2[zh]))] // Simplify;
Tp[m_, zh_] := D[T[m, zh], zh] // Simplify;
Fdiff[m_?NumericQ] := NIntegrate[s[y] Tp[m, y], {y, 3, 100}] - NIntegrate[s[y] Tp[m, y], {y, 7, 100}]
FindRoot[Chop[Fdiff[m]] == 0, {m, 0.048}, AccuracyGoal -> 10, WorkingPrecision -> 10]
NIntegrate::inumr: The integrand (-((y^6 (1+<<1>>)^(6069/<<3>>) <<1>> (1-(227 <<1>> (Power[<<2>>] <<1>>+<<1>>))/(500 (-1+<<1>>)^2)))/(4000000000000000000000000000000000000000000000000000000000000 <<2>> <<1>>^2))+<<1>><<1>><<1>>+<<1>>/<<1>>)/(4 y^3 (1+(1613 y^2)/100000)^(6069/500)) has evaluated to non-numerical values for all sampling points in the region with boundaries {{4,28.}}.
ListPlot[Table[{i,Chop[Fdiff[i]]},{i,-56/1000,56/1000,8/1000}]]
then that does not look promising forFindRoot
and I wonder whether it may have wandered far away from your starting point and possibly begun passing strange things toFdiff
and this may be related to the error message that you are seeing. $\endgroup$