I have a function intSL[a,zl,zh]
where I want to compute its derivative with respect to zl
given some values of a
and zh
. I also want to plot it wrt to zl
with the range 0 < zl < 1
.
However, there are some zl
where my function displays an error message and produces a complex value. When I compare results that are complex valued to the result that are not, it seems like their corresponding real parts has a trend and so I think I could just eliminate the imaginary part (I think???), but I do not know how to do it.
Here is my code,
d = 3;
torootL[a_?NumericQ, t_?NumericQ, zl_?NumericQ, zh_?NumericQ] := a - NIntegrate[(zl y^d)/Sqrt[(1 - (zl/zh)^(d + 1) y^(d + 1)) (1 + t^2 (1 - (zl/zh)^(d + 1))^-1 - y^(2 d))], {y, 0, 1}]
tz[a_?NumericQ, zl_?NumericQ, zh_?NumericQ] := t /. FindRoot[torootL[a, t, zl, zh], {t, 1, -1000, 10000}]
intSL[a_?NumericQ, zl_?NumericQ, zh_?NumericQ] := NIntegrate[With[{b = zl/zh}, (((-1)/(d - 1)) (zl^(2 d) (1 + tz[a, zl, zh]^2 (1 - (zl/zh)^(d + 1))^(-1)))^(-1) zl^(2 d)) x^d ((1 - (b x)^(d + 1))/(1 - (zl^(2 d) (1 + tz[a, zl, zh]^2 (1 - (zl/zh)^(d + 1))^(-1)))^(-1) (zl x)^(2 d)))^(1/2) - ((b^(d + 1) (d + 1))/(2 (d - 1))) x ((1 - (zl^(2 d) (1 + tz[a, zl, zh]^2 (1 - (zl/zh)^(d + 1))^(-1)))^(-1) (zl x)^(2 d))/(1 - (b x)^(d + 1)))^(1/2) + (b^(d + 1)x)/((1 - (b x)^(d + 1)) (1 - (zl^(2 d) (1 + tz[a, zl, zh]^2 (1 - (zl/zh)^(d + 1))^(-1)))^(-1) (zl x)^(2 d)))^(1/2)], {x, 0, 0.98, 0.99, 1}, MaxRecursion -> 20, PrecisionGoal -> 6]
Here is an example of the evaluation of the derivative,
intSLL[zl_] := Evaluate[D[intSL[0.01, zl, 1], zl]]
In[58]:= intSLL[0.3]
During evaluation of In[58]:= FindRoot::jsing: Encountered a singular Jacobian at the point {t} = {-5.99038*10^-9}. Try perturbing the initial point(s).
During evaluation of In[58]:= FindRoot::jsing: Encountered a singular Jacobian at the point {t} = {-5.99038*10^-9}. Try perturbing the initial point(s).
During evaluation of In[58]:= FindRoot::jsing: Encountered a singular Jacobian at the point {t} = {-5.99038*10^-9}. Try perturbing the initial point(s).
During evaluation of In[58]:= General::stop: Further output of FindRoot::jsing will be suppressed during this calculation.
During evaluation of In[58]:= FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.
During evaluation of In[58]:= FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.
During evaluation of In[58]:= FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.
During evaluation of In[58]:= General::stop: Further output of FindRoot::lstol will be suppressed during this calculation.
During evaluation of In[58]:= FindRoot::reged: The point {10000.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.
During evaluation of In[58]:= FindRoot::reged: The point {10000.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.
During evaluation of In[58]:= FindRoot::reged: The point {10000.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.
During evaluation of In[58]:= General::stop: Further output of FindRoot::reged will be suppressed during this calculation.
Out[58]= 0.0149288
In[57]:= intSLL[0.4]
During evaluation of In[57]:= FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.
During evaluation of In[57]:= FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.
During evaluation of In[57]:= FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.
During evaluation of In[57]:= General::stop: Further output of FindRoot::lstol will be suppressed during this calculation.
During evaluation of In[57]:= FindRoot::jsing: Encountered a singular Jacobian at the point {t} = {-6.30218*10^-9}. Try perturbing the initial point(s).
During evaluation of In[57]:= FindRoot::jsing: Encountered a singular Jacobian at the point {t} = {-6.30218*10^-9}. Try perturbing the initial point(s).
During evaluation of In[57]:= FindRoot::jsing: Encountered a singular Jacobian at the point {t} = {-6.30218*10^-9}. Try perturbing the initial point(s).
During evaluation of In[57]:= General::stop: Further output of FindRoot::jsing will be suppressed during this calculation.
During evaluation of In[57]:= FindRoot::reged: The point {10000.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.
During evaluation of In[57]:= FindRoot::reged: The point {10000.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.
During evaluation of In[57]:= FindRoot::reged: The point {10000.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.
During evaluation of In[57]:= General::stop: Further output of FindRoot::reged will be suppressed during this calculation.
Out[57]= 0.00650273
In[55]:= intSLL[0.5]
Out[55]= 0.00353467
In[56]:= intSLL[0.6]
During evaluation of In[56]:= FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.
During evaluation of In[56]:= FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.
During evaluation of In[56]:= FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.
During evaluation of In[56]:= General::stop: Further output of FindRoot::lstol will be suppressed during this calculation.
During evaluation of In[56]:= NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in y near {y} = {0.984824086012257}. NIntegrate obtained 0.0293841 -0.119444 I and 0.0017267736029825806` for the integral and error estimates.
During evaluation of In[56]:= NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in y near {y} = {0.984824086012257}. NIntegrate obtained 0.0293841 -0.119444 I and 0.0017267736029825806` for the integral and error estimates.
During evaluation of In[56]:= NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in y near {y} = {0.984824086012257}. NIntegrate obtained 0.0293841 -0.119444 I and 0.001726773577114529` for the integral and error estimates.
During evaluation of In[56]:= General::stop: Further output of NIntegrate::ncvb will be suppressed during this calculation.
During evaluation of In[56]:= FindRoot::reged: The point {1.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.
During evaluation of In[56]:= FindRoot::reged: The point {1.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.
During evaluation of In[56]:= FindRoot::reged: The point {1.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.
During evaluation of In[56]:= General::stop: Further output of FindRoot::reged will be suppressed during this calculation.
During evaluation of In[56]:= NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small.
During evaluation of In[56]:= NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small.
During evaluation of In[56]:= NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small.
During evaluation of In[56]:= General::stop: Further output of NIntegrate::slwcon will be suppressed during this calculation.
Out[56]= 0.00225041 + 8.62966*10^-11 I
In[59]:= intSLL[0.7]
During evaluation of In[59]:= NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small.
During evaluation of In[59]:= NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in y near {y} = {0.99762205831973036103399454788132061366923153400421142578125000000}. NIntegrate obtained 0.00330503 -0.0437457 I and 0.0008224862881109875` for the integral and error estimates.
During evaluation of In[59]:= NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small.
During evaluation of In[59]:= NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in y near {y} = {0.99762205831973036103399454788132061366923153400421142578125000000}. NIntegrate obtained 0.00330503 -0.0437457 I and 0.0008224862881109875` for the integral and error estimates.
During evaluation of In[59]:= NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small.
During evaluation of In[59]:= General::stop: Further output of NIntegrate::slwcon will be suppressed during this calculation.
During evaluation of In[59]:= NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in y near {y} = {0.99762205831973036103399454788132061366923153400421142578125000000}. NIntegrate obtained 0.00330503 -0.0437457 I and 0.0008224862758539473` for the integral and error estimates.
During evaluation of In[59]:= General::stop: Further output of NIntegrate::ncvb will be suppressed during this calculation.
During evaluation of In[59]:= FindRoot::reged: The point {1.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.
During evaluation of In[59]:= FindRoot::reged: The point {1.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.
During evaluation of In[59]:= FindRoot::reged: The point {1.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.
During evaluation of In[59]:= General::stop: Further output of FindRoot::reged will be suppressed during this calculation.
Out[59]= 0.0016139 + 2.5821*10^-6 I
To summarize the sample result, intSLL[zl]
produces the values for the corresponding zl
0.0149288 zl=0.3 (with error)
0.00650273 zl=0.4 (with error)
0.00353467 zl=0.5
0.00225041 + 8.62966*10^-11 I zl=0.6 (with error)
0.0016139 + 2.5821*10^-6 I zl=0.7 (with error)
You can see the trend of the values of the real part.