0
$\begingroup$

I have a function of two variables tz[0.1, zqes, zh] to which I want to find its values for a given range of zqes and zh.

The first problem is, I want tz[0.1, zqes, zh] to give a value for say, zqes=0.937858 and zh=1, zqes=9.30684 and zh=10, and so on. The Table that I wrote below evaluates tz[0.1, zqes, zh] for zqes=0.937858 and ALL zh, then proceeds to zqes=9.30684 and ALL zh again, and so on. So what I want should produce only 11 values for tz[0.1, zqes, zh], how should I do this?

The second problem is, tz[0.1, zqes, zh] will have a range of around ~[-155, -1.47], to which tz[0.1, 0.937858, 1] = -1.47 (Max value for zh=1) and tz[0.1, 93.0506, 100] = -155 (Min value for zh=100). In the FindRoot line of my code I set the search range to be {t, -1.2, -200, 0} but why is finding tz[0.1, zqes, zh] produces some error like The point {-1.2} is at the edge of the search region...

d = 3;
ag = 6;
pg = 6;
wp = 10;
torootL[al_?NumericQ, t_?NumericQ, zl_?NumericQ, zh_?NumericQ] := al - ((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}, AccuracyGoal -> ag, PrecisionGoal -> pg, WorkingPrecision -> wp, Method -> "GlobalAdaptive"]
tz[al_?NumericQ, zl_?NumericQ, zh_?NumericQ] := t /. FindRoot[torootL[al, t, zl, zh], {t, -1.2, -200, 0}, AccuracyGoal -> ag, PrecisionGoal -> pg, WorkingPrecision -> wp]

In[108]:= tzList = Table[tz[0.1, zqes, zh], {zqes, {0.937858, 9.30684, 18.6124, 27.9182, 37.2237, 46.5288, 55.8341, 65.1388, 74.4432, 83.7471, 93.0506}}, {zh, {1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100}}]

During evaluation of In[108]:= NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in x near {x} = {86.5934328105432153458601759241399254869861325536822348289974}. NIntegrate obtained 1.56949422762797476134702692399833712204785593227582473073534-121.292776422049311975665999308525652348615116650629201734954 I and 0.598935835823095879488732088256231272482268679212473514418771`60. for the integral and error estimates.

During evaluation of In[108]:= NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in x near {x} = {86.5934328105432153458601759241399254869861325536822348289974}. NIntegrate obtained 1.56949422762797476134702692399833712204785593227582473073534-121.292776422049311975665999308525652348615116650629201734954 I and 0.598935835823095879488732088256231272482268679212473514418771`60. for the integral and error estimates.

During evaluation of In[108]:= NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in x near {x} = {86.5934328105432153458601759241399254869861325536822348289974}. NIntegrate obtained 1.56949427826409832284230728405949350830183983616138886512567-121.292776353861452832569246171990054728109868720739971672617 I and 0.598935827627696875159785645877019653242788626650765046709032`60. for the integral and error estimates.

During evaluation of In[108]:= General::stop: Further output of NIntegrate::ncvb will be suppressed during this calculation.

During evaluation of In[108]:= FindRoot::reged: The point {-1.2} is at the edge of the search region {-200.0000000000000,0} in coordinate 1 and the computed search direction points outside the region.

During evaluation of In[108]:= 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[108]:= 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[108]:= 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[108]:= General::stop: Further output of NIntegrate::slwcon will be suppressed during this calculation.

During evaluation of In[108]:= FindRoot::reged: The point {-1.2} is at the edge of the search region {-200.0000000000000,0} in coordinate 1 and the computed search direction points outside the region.

During evaluation of In[108]:= FindRoot::reged: The point {-1.2} is at the edge of the search region {-200.0000000000000,0} in coordinate 1 and the computed search direction points outside the region.

During evaluation of In[108]:= General::stop: Further output of FindRoot::reged will be suppressed during this calculation.

Out[108]= {{-1.471551293, -2.215779632, -2.215814401, -2.215816261, \
-2.215816574, -2.215816660, -2.215816691, -2.215816704, -2.215816710, \
-2.215816713, -2.215816715}, {-1.2, -15.50176577, -22.97536070, \
-23.20017521, -23.23716426, -23.24723138, -23.25084319, -23.25239079, \
-23.25314176, -23.25354138, -23.25376974}, {-1.2, -1.2, -31.01646875, \
-44.66098537, -45.96631187, -46.29912053, -46.41638235, -46.46628998, \
-46.49043553, -46.50326522, -46.51059034}, {-1.2, -1.2, -1.2, \
-46.52851902, -65.07238194, -68.00769950, -68.95369435, -69.34412174, \
-69.53052120, -69.62891714, -69.68489720}, {-1.2, -1.2, -1.2, -1.2, \
-62.04170567, -84.54277049, -89.32829175, -91.11761198, -91.93933961, \
-92.36517587, -92.60507659}, {-1.2, -1.2, -1.2, -1.2, -1.2, \
-77.55674550, -103.3216290, -110.0106225, -112.7868873, -114.1644888, \
-114.9236328}, {-1.2, -1.2, -1.2, -1.2, -1.2, -1.2, -93.07071265, \
-121.5803427, -130.1463546, -133.9919437, -136.0163442}, {-1.2, -1.2, \
-1.2, -1.2, -1.2, -1.2, -1.2, -108.5876350, -139.4370608, \
-149.8147737, -154.7709946}, {-1.2, -1.2, -1.2, -1.2, -1.2, -1.2, \
-1.2, -1.2, -124.1060283, -156.9768022, -169.0842074}, {-1.2, -1.2, \
-1.2, -1.2, -1.2, -1.2, -1.2, -1.2, -1.2, -139.6268987, \
-174.2617740}, {-1.2, -1.2, -1.2, -1.2, -1.2, -1.2, -1.2, -1.2, -1.2, \
-1.2, -155.1497506}}
```
$\endgroup$

2 Answers 2

1
$\begingroup$

"MapThread" is your friend. Here is your corrected code:

d = 3;
ag = 6;
pg = 6;
wp = 10;
torootL[al_?NumericQ, t_?NumericQ, zl_?NumericQ, zh_?NumericQ] := 
 al - ((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}, AccuracyGoal -> ag, 
    PrecisionGoal -> pg, WorkingPrecision -> wp, 
    Method -> "GlobalAdaptive"]
tz[al_?NumericQ, zl_?NumericQ, zh_?NumericQ] := 
 t /. FindRoot[torootL[al, t, zl, zh], {t, -1.2, -200, 0}, 
   AccuracyGoal -> ag, PrecisionGoal -> pg, WorkingPrecision -> wp]

tzList = MapThread[
  tz[0.1, #1, #2] &, {{0.937858, 9.30684, 18.6124, 27.9182, 37.2237, 
    46.5288, 55.8341, 65.1388, 74.4432, 83.7471, 93.0506}, {1, 10, 20,
     30, 40, 50, 60, 70, 80, 90, 100}}]


(* {-1.471551293, -15.50176577, -31.01646875, -46.52851902, \
-62.04170567, -77.55674550, -93.07071265, -108.5876350, -124.1060283, \
-139.6268987, -155.1497506} *)
$\endgroup$
2
  • $\begingroup$ The first one works but the last one does not work. $\endgroup$
    – mathemania
    Commented Jun 1, 2021 at 14:28
  • 1
    $\begingroup$ Sorry the last one was a copy/ paste error, it does not belong to my answer. $\endgroup$ Commented Jun 1, 2021 at 16:26
1
$\begingroup$

Try

MapThread[{#1, #2, tz[0.1, #1, #2]} &
, {{0.937858, 9.30684, 18.6124,27.9182, 37.2237, 46.5288, 55.8341, 65.1388, 74.4432, 83.7471,93.0506}
, {1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100}}]
(*{{0.937858, 1, -1.471551293}, {9.30684, 10, -15.50176577}, {18.6124,20, -31.01646875}, {27.9182, 30, -46.52851902}, {37.2237,40, -62.04170567}, {46.5288, 50, -77.55674550}, {55.8341,60, -93.07071265}, {65.1388, 70, -108.5876350}, {74.4432,80, -124.1060283}, {83.7471, 90,-139.6268987}, {93.0506,100, -155.1497506}}*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.