3

I got a lot of error message when running the following codes:

prdiff[dp_, group_] := NIntegrate[2*2*1/(2*Pi) Cos[delta*t]*Product[Sin[c*Q[[group]]^i*t]/(c*Q[[group]]^i*t), {i, k + 1,k + h}]/c*Product[UnitStep[c - Abs[cn[[i, group]]]]/(2*c), {i, 3, k + 1}], {t, 0.0000001, Infinity}, {c, 0.0000001, Infinity}, {delta,0.0000001, dp}]/Integrate[1/c*Product[UnitStep[c - Abs[cn[[i, group]]]]/(2*c), {i, 3, k + 1}], {c, 0.0000001, Infinity}] - p
dListA = Table[FindRoot[prdiff[d, group], {d, d /. dListC[[group, 1]]}], {group, 1,16}]

where

Q={0.374823, 0.472246, 0.540587, 0.594993, 0.640938, 0.681097,0.717011, 0.749645, 0.779662, 0.807531, 0.833598, 0.858129,0.881331,0.903376, 0.924391, 0.944492}
k=2
h=10
dListC={{d -> 1.05872}, {d -> 2.32267}, {d -> 3.42827}, {d -> 4.32914}, {d ->5.14583}, {d -> 5.86437}, {d -> 6.50946}, {d -> 7.13946}, {d -> 7.77764}, {d -> 8.35564}, {d -> 9.03415}, {d -> 9.68592}, {d ->10.4552}, {d -> 11.2388}, {d -> 12.1519}, {d -> 13.1069}}
p=0.9544
cn={{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {-1.33739, -1.39482, -1.30994, -1.18525, -1.07646, -0.975324,-0.883788, -0.806052, -0.739899, -0.67623, -0.626402,-0.578394,-0.539806, -0.503205, -0.47299, -0.444406}, {-0.451706, -0.392128,-0.358641, -0.383565, -0.423396, -0.466082, -0.53215,-0.60404,-0.653776, -0.714855, -0.783097, -0.845636, -0.913242, -0.951801,-0.993216, -1.09363}, {0.646079, 0.567603, 0.491802, 0.382459, 0.288999, 0.150248, 0.0691451, -0.000652212, -0.115531, -0.177339, -0.259667,-0.308962, -0.473129, -0.633472, -0.87269, -1.56666}, {1.77469, 2.03892, 2.53728, 2.71311, 2.98287, 3.1305, 3.18962, 3.21899, 3.28681, 3.2669, 3.29087, 3.26718, 3.3841, 3.45476, 3.61692, 4.32612}}

the error messages are:

NIntegrate::nlim: delta = d is not a valid limit of integration.

NIntegrate::nlim: delta = d is not a valid limit of integration.

NIntegrate::nlim: delta = d is not a valid limit of integration.

General::stop: Further output of NIntegrate::nlim will be suppressed during this calculation.

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::eincr: The global error of the strategy GlobalAdaptive has increased more than 2000 times. The global error is expected to decrease monotonically after a number of integrand evaluations. Suspect one of the following: the working precision is insufficient for the specified precision goal; the integrand is highly oscillatory or it is not a (piecewise) smooth function; or the true value of the integral is 0. Increasing the value of the GlobalAdaptive option MaxErrorIncreases might lead to a convergent numerical integration. NIntegrate obtained 0.36070001885559877` and 0.0020873226492962383` for the integral and error estimates.

NIntegrate::izero: Integral and error estimates are 0 on all integration subregions. Try increasing the value of the MinRecursion option. If value of integral may be 0, specify a finite value for the AccuracyGoal option.

NIntegrate::izero: Integral and error estimates are 0 on all integration subregions. Try increasing the value of the MinRecursion option. If value of integral may be 0, specify a finite value for the AccuracyGoal option.

NIntegrate::izero: Integral and error estimates are 0 on all integration subregions. Try increasing the value of the MinRecursion option. If value of integral may be 0, specify a finite value for the AccuracyGoal option.

General::stop: Further output of NIntegrate::izero will be suppressed during this calculation.

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::eincr: The global error of the strategy GlobalAdaptive has increased more than 2000 times. The global error is expected to decrease monotonically after a number of integrand evaluations. Suspect one of the following: the working precision is insufficient for the specified precision goal; the integrand is highly oscillatory or it is not a (piecewise) smooth function; or the true value of the integral is 0. Increasing the value of the GlobalAdaptive option MaxErrorIncreases might lead to a convergent numerical integration. NIntegrate obtained 0.36070001885559877` and 0.0020873226492962383` 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.

General::stop: Further output of NIntegrate::slwcon will be suppressed during this calculation.

NIntegrate::eincr: The global error of the strategy GlobalAdaptive has increased more than 2000 times. The global error is expected to decrease monotonically after a number of integrand evaluations. Suspect one of the following: the working precision is insufficient for the specified precision goal; the integrand is highly oscillatory or it is not a (piecewise) smooth function; or the true value of the integral is 0. Increasing the value of the GlobalAdaptive option MaxErrorIncreases might lead to a convergent numerical integration. NIntegrate obtained 0.36070001964905846` and 0.002087321948358613` for the integral and error estimates.

General::stop: Further output of NIntegrate::eincr will be suppressed during this calculation.

Divide::infy: Infinite expression -(0.0103937/0.) encountered.

Divide::infy: Infinite expression -(0.0103937/0.) encountered.

Divide::infy: Infinite expression -(0.0103937/0.) encountered.

General::stop: Further output of Divide::infy will be suppressed during this calculation.

FindRoot::jsing: Encountered a singular Jacobian at the point {d} = {1.05872}. Try perturbing the initial point(s).

FindRoot::jsing: Encountered a singular Jacobian at the point {d} = {2.32267}. Try perturbing the initial point(s).

FindRoot::jsing: Encountered a singular Jacobian at the point {d} = {3.42827}. Try perturbing the initial point(s).

General::stop: Further output of FindRoot::jsing will be suppressed during this calculation.

NIntegrate::inumr: The integrand (2.78145*10^11 Cos[1.1397 d] Sin[0.360095 c] <<8>> Sin[0.24526 (0. +c)] UnitStep[-0.975324+c])/(0. +c)^12 has evaluated to non-numerical values for all sampling points in the region with boundaries {{\[Infinity],1.}}.

NIntegrate::inumr: The integrand (2.78145*10^11 Cos[1.1397 d] Sin[0.360095 c] <<8>> Sin[0.24526 (0. +c)] UnitStep[-0.975324+c])/(0. +c)^12 has evaluated to non-numerical values for all sampling points in the region with boundaries {{\[Infinity],1.}}.

NIntegrate::inumr: The integrand (2.78145*10^11 Cos[1.1397 d] Sin[0.360095 c] <<8>> Sin[0.24526 (0. +c)] UnitStep[-0.975324+c])/(0. +c)^12 has evaluated to non-numerical values for all sampling points in the region with boundaries {{\[Infinity],1.}}.

General::stop: Further output of NIntegrate::inumr will be suppressed during this calculation.

it seems that my Integrand function has some singularity, but I couldn't find them since all integral intervals do not contain 0.

Update:I find that the most important error is

Divide::infy: Infinite expression -(0.0103937/0.) encountered.

Because I find that if prdiff[d,group]=x, then the error shows

Divide::infy: Infinite expression -(x/0.) encountered.

For example, if I try

prdiff[1, 1]

I get

0.00822213

then I try

FindRoot[prdiff[d, 1] == 0, {d, 1}]

then the error message says

Divide::infy: Infinite expression -(0.00822213/0.) encountered.

It is very strange because there is no expression like prdiff(d,group)/0. And since the prdiff function could give a normal value, the error should not be in the NIntegrate or Integrate function and may in the FindRoot.How should I do?

Michael E2
  • 235,386
  • 17
  • 334
  • 747
Perry_W
  • 135
  • 5
  • 2
    Please show all the code needed -- you are missing definitions for cn[[ ]]. Next, break apart the code and see which piece is giving the problem. For instance, you have an Integrate and an NIntegrate -- which is giving the error messages? – bill s Mar 24 '18 at 14:01
  • I have edited the question. Thanks for your remind. – Perry_W Mar 24 '18 at 15:14
  • When you do prdiff[1,1] you do not get 0.00822213. You get "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." followed by the number 0.00822213. So look at your NIntegrate. – bill s Mar 24 '18 at 16:23
  • But what about the "Divide::infy:" error? It shows only when FindRoot is used. Although I get some messages when running prdiff[1,1], the result is correct. I couldn't find any problems in my NIntegrate even after many checks. – Perry_W Mar 24 '18 at 16:44
  • 1
    I usually start work on the first error, not the 20th or so. Often one error leads to another. Therefore your choice for the title seems misleading. – Michael E2 Mar 24 '18 at 20:20
  • Possible duplicate: https://mathematica.stackexchange.com/questions/18393 – Michael E2 Mar 24 '18 at 20:48

1 Answers1

1

The principal problem is the need for _?NumericQ on the variables of prdiff, which probably makes this a duplicate of What are the most common pitfalls awaiting new users?. (For one of the variables, I used the more specific _Integer?Positive instead. I also precomputed the Integrate[..] factors for a modest speed up. The whole takes a very, very long time, due to the multiple calls to a 3D NIntegrate.)

iTab = Table[
   Integrate[
    1/c*Product[
      UnitStep[c - Abs[cn[[i, group]]]]/(2*c), {i, 3, k + 1}], {c, 
     0.0000001, Infinity}],
   {group, 1, 16}];

prdiff[dp_?NumericQ, group_Integer?Positive] := 
 NIntegrate[
    2*2*1/(2*Pi) Cos[delta*t]*
     Product[Sin[c*Q[[group]]^i*t]/(c*Q[[group]]^i*t), {i, k + 1, 
        k + h}]/c*
     Product[UnitStep[c - Abs[cn[[i, group]]]]/(2*c), {i, 3, 
       k + 1}], {t, 0.0000001, Infinity}, {c, 0.0000001, 
     Infinity}, {delta, 0.0000001, dp}]/iTab[[group]] - p
Monitor[
 dListA = 
  Table[FindRoot[prdiff[d, group], {d, d /. dListC[[group, 1]]}, 
    PrecisionGoal -> 4,   (* b/c of NIntegrate, probably can't get high precision *)
    AccuracyGoal -> 3],
  {group, 1, 16}],
 {d, group}]

(* some time later... *)
dListA
(*  {{d -> 0.81095}, ..., {d -> 9.55454}}  *)
Michael E2
  • 235,386
  • 17
  • 334
  • 747