1
$\begingroup$

I have the following error at FindRoot using a function with NIntegrate:

NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in y near {y} = {10.9130359139484499045371956829929066187800934528695506742224097252}. NIntegrate obtained 2.2676305277968822`*^-14 and 9.641852330564264`*^-13 for the integral and error estimates. NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in y near {y} = {10.9130359139484499045371956829929066187800934528695506742224097252}. NIntegrate obtained 2.2676305277968822`*^-14 and 9.641852330564264`*^-13 for the integral and error estimates. 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. NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in y near {y} = {10.1455}. NIntegrate obtained -3.85109*10^-16 and 1.5965726624074823`*^-16 for the integral and error estimates. General::stop: Further output of NIntegrate::ncvb will be suppressed during this calculation. 

My code:

b = -35/100; d = 9; u[y_] := (Tanh[a*(y - d)] + Tanh[a*d])/(1 + Tanh[a*d]) + b*Sqrt[3]*y/d*Exp[-1.5*(y/d)^2 + 0.5]; f[a_?NumericQ] := NIntegrate[u[y] (1 - u[y]), {y, 0, 80}]; a = Rationalize[FindRoot[f[a] == 1, {a, 14/100}][[1, 2]], 0]; g[ydd_?NumericQ] := NIntegrate[u[y], {y, 0, ydd}]; FindRoot[g[ydd], {ydd, 10}] 

What is wrong?

$\endgroup$
0

2 Answers 2

0
$\begingroup$

"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."

So use a higher WorkingPrecision

Clear[a] b = -35/100; d = 9; u[y_] := (Tanh[a*(y - d)] + Tanh[a*d])/(1 + Tanh[a*d]) + b*Sqrt[3]*y/d*Exp[-3/2*(y/d)^2 + 1/2]; f[a_?NumericQ] := NIntegrate[u[y] (1 - u[y]), {y, 0, 80}]; a = Rationalize[a /. FindRoot[f[a] == 1, {a, 14/100}], 0]; g[ydd_?NumericQ] := NIntegrate[u[y], {y, 0, Rationalize[ydd, 0]}, WorkingPrecision -> 21]; FindRoot[g[ydd], {ydd, 10}, WorkingPrecision -> 20] (* {ydd -> 10.913036109675691159} *) 
$\endgroup$
2
$\begingroup$

Set an explicit value for AccuracyGoal within NIntegrate:

g[ydd_?NumericQ] := NIntegrate[u[y], {y, 0, ydd}, AccuracyGoal -> 10] FindRoot[g[ydd], {ydd, 10}] (* Out: {ydd -> 10.913} *) 

Even AccuracyGoal -> Automatic would work in this case. I suspect the difficulty may arise because your integral value approaches zero. The above returns the same result as your code, but without warnings.

A plot supports this results:

Plot[ NIntegrate[u[y], {y, 0, ydd}], {ydd, 10.91, 10.915}, AxesOrigin -> {Automatic, 0}, Epilog -> {Red, PointSize[0.02], Point[{10.913036109679442, 0}]} ] 

Mathematica graphics

$\endgroup$
1
  • $\begingroup$ I would add that the AccuracyGoal should be at least as high as the AccuracyGoal for FindRoot (and probably a little higher). Which it is in this example. $\endgroup$ Commented Jul 5, 2018 at 0:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.