I have a function functionSL
as a function of t
(t<0
) where I want to find the extremum of the function and also find at which t
it occurs. I took the derivative of functionSL
with t
which I wrote it as the function functionSLD
.
d = 3;
torootL[a_?NumericQ, t_?NumericQ, zl_?NumericQ, zh_?NumericQ] := a - ((2 zl Sqrt[(1 + t^2 (1 - (zl/zh)^(d + 1))^-1)^-1])/((d + 1) (zl/zh)^(d + 1))) NIntegrate[(x)/Sqrt[(1 - x^2) (1 - (((1 + t^2 (1 - (zl/zh)^(d + 1))^-1)^-1) (zl/zh)^-6) x^3)], {x, 0, (zl/zh)^2}]
zs[a_?NumericQ, t_?NumericQ, zh_?NumericQ] := zl /. FindRoot[torootL[a, t, zl, zh], {zl, 0.5, 0, 1}]
intSL1[a_?NumericQ, t_?NumericQ, zh_?NumericQ] := ((-1/(d - 1)) (zs[a, t, zh]^(2 d) (1 + t^2 (1 - (zs[a, t, zh]/zh)^(d + 1))^-1))^-1 zs[a, t, zh]^(2 d))*NIntegrate[x^d ((1 - (zs[a, t, zh]/zh)^(d + 1) x^(d + 1))/(1 - (zs[a, t, zh]^(2 d) (1 + t^2 (1 - (zs[a, t, zh]/zh)^(d + 1))^-1))^-1 (zs[a, t, zh] x)^(2 d)))^(1/2), {x, 0, 1}]
intSL2[a_?NumericQ, t_?NumericQ, zh_?NumericQ] := ((-(zs[a, t, zh]/zh)^(d + 1) (d + 1))/(2 (d - 1))) * NIntegrate[x ((1 - (zs[a, t, zh]^(2 d) (1 + t^2 (1 - (zs[a, t, zh]/zh)^(d + 1))^-1))^-1 (zs[a, t, zh] x)^(2 d))/(1 - (zs[a, t, zh]/zh)^(d + 1) x^(d + 1)))^(1/2), {x, 0, 1}]
intSL3[a_?NumericQ, t_?NumericQ, zh_?NumericQ] := (zs[a, t, zh]/zh)^(d + 1) * NIntegrate[x/((1 - (zs[a, t, zh]/zh)^(d + 1) x^(d + 1)) (1 - (zs[a, t, zh]^(2 d) (1 + t^2 (1 - (zs[a, t, zh]/zh)^(d + 1))^-1))^-1 (zs[a, t, zh] x)^(2 d)))^(1/2), {x, 0, 1}]
functionSL[a_?NumericQ, t_?NumericQ, zh_?NumericQ] := ((-((1 - (zs[a, t, zh]^(2 d) (1 + t^2 (1 - (zs[a, t, zh]/zh)^(d + 1))^-1))^-1 zs[a, t, zh]^(2 d)) (1 - (zs[a, t, zh]/zh)^(d + 1)))^(1/2)/(d - 1)) + intSL1[a, t, zh] + intSL2[a, t, zh] + intSL3[a, t, zh] + 1)/(4 zs[a, t, zh]^(d - 1))
functionSLD[t_] := Evaluate[Derivative[0, 1, 0][functionSL][0.01, t, 1]]
The plot of functionSL
is shown below,
I took some sample values of functionSLD
for some t
,
In[66]:= functionSLD[-15] // Quiet // AbsoluteTiming
Out[66]= {70.7648, 0.0477369}
In[68]:= functionSLD[-17] // Quiet // AbsoluteTiming
Out[68]= {108.509, 0.0424448}
In[69]:= functionSLD[-17.5] // Quiet // AbsoluteTiming
Out[69]= {126.48, -0.0112613}
From this evaluation, functionSLD
passes the $t$ axis somewhere between -17 and -17.5.
However, by finding the root of functionSLD
, something is off
In[63]:= FindRoot[functionSLD[t] == 0, {t, -17.3, -17.5, -17}] // Quiet // AbsoluteTiming
Out[63]= {1218.97, {t -> -17.}}
Why did FindRoot
give a solution of t=-17
? Clearly, from the evaluation of functionSLD
at t=-17
it gives functionSLD[-17] == 0.0424448
which is not 0!
Any help?
EDIT:
I found the culprit to my problem. It has to do with how I chose the initial point in FindRoot
in my code of zs[a_?NumericQ, t_?NumericQ, zh_?NumericQ]
.
If I choose the initial point as 0.5
(it could be lower) so that FindRoot[torootL[a, t, zl, zh], {zl, 0.5, 0, 1}]
, then I get the plot,
If I choose the initial point as 0.9
so that FindRoot[torootL[a, t, zl, zh], {zl, 0.9, 0, 1}]
, then I get the plot,
which is exactly what I am searching for, clearly there is a minimum around t=-15.5
. The reason for this is I expect an extremum at around $zl=0$ (even if I choose zl=0.5
in Mathematica somehow it still plots the correct extremum) which corresponds to t=0
which is the first plot and at around $zl=0.9$ (I think it still works even I choose zl=0.8
but the computed value of the other extremum is $zl=0.9$) which corresponds to t=-15.5
which is the second plot. So the issue now becomes, how to make FindRoot
find these two extremum points at the same plot. I do not know how to add two initial points in FindRoot
.
zs[a, t, zh]
is undefined I think. $\endgroup$zs[a, t, zh]
was in the wrong place in the code , it can now be seen. $\endgroup$functionSLL
andfunctionSLLP
? $\endgroup$functionSLD
vst
, plotting it took a very long time so I aborted it, then I tried evaluating at some sample points as I showed above. At some points there is no problem evaluating but att = -17
it produced an error which was hidden by the commandQuiet
, I'm not sure if doing that is correct even though it produced a value (maybe it's a wrong value?). Att = -17.5
it just takes so long so I just aborted it again. I want to seefunctionSLD
crosses thet
axis so I am trying to see the plot too. $\endgroup$