Prev: How to dynamically build a list of rules
Next: Pade Approximation (further generalizations?---feature request)
From: sukhrob on 14 Apr 2010 05:16 Hi everybody, I'm using Mathematica 7.0 , i would like integrate numerically something like Fourier coefficients, my programe code contains: M = 50; f[t_] = 100 Sin[5 t]; basis = Table[Sin[n t], {n, 1, M}]; coef = 2/Pi*Table[NIntegrate[f[t] Sin[n t], {t, 0, Pi}], {n, 1, M}] in result it gives : NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in t near {t} = {2.47283}. NIntegrate obtained -3.88578*10^-15 and 7.654706546923104`*^-15 for the integral and error estimates. >> NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in t near {t} = {2.47283}. NIntegrate obtained -3.19189*10^-15 and 1.8799124112361456`*^-14 for the integral and error estimates. >> NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in t near {t} = {0.00254055}. NIntegrate obtained 1.2045919817182948`*^-14 and 9.105942246869344`*^-13 for the integral and error estimates. >> General::stop: Further output of NIntegrate::ncvb will be suppressed during this calculation. >> Can anyone help me to solve that problem. Any help would be very much appreciated. Thanks in advance Sukhrob -- View this message in context: http://old.nabble.com/NIntegrate-Confusion-tp28239593p28239593.html Sent from the MathGroup mailing list archive at Nabble.com.
From: Kevin J. McCann on 16 Apr 2010 05:50 I don't think you have a real problem. NIntegrate is doing a relative error check (by default), and when the answer is close to zero, this presents a divide by a small number problem. You can use absolute accuracy as the accuracy goal by specifying the number of decimal places accuracy you want. For example, with your problem, you can specify 12 place accuracy as follows: coef = 2/\[Pi] Table[ NIntegrate[f[t] Sin[n t], {t, 0, \[Pi]} , AccuracyGoal -> 12], {n, 1, M}] Kevin sukhrob wrote: > Hi everybody, > I'm using Mathematica 7.0 , i would like integrate numerically something > like Fourier coefficients, my programe code contains: > > M = 50; f[t_] = 100 Sin[5 t]; > > basis = Table[Sin[n t], {n, 1, M}]; > > coef = 2/Pi*Table[NIntegrate[f[t] Sin[n t], {t, 0, Pi}], {n, 1, M}] > > in result it gives : > > NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after > 9 recursive bisections in t near {t} = {2.47283}. NIntegrate obtained > -3.88578*10^-15 and 7.654706546923104`*^-15 for the integral and error > estimates. >> > NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after > 9 recursive bisections in t near {t} = {2.47283}. NIntegrate obtained > -3.19189*10^-15 and 1.8799124112361456`*^-14 for the integral and error > estimates. >> > > NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after > 9 recursive bisections in t near {t} = {0.00254055}. NIntegrate obtained > 1.2045919817182948`*^-14 and 9.105942246869344`*^-13 for the integral and > error estimates. >> > > General::stop: Further output of NIntegrate::ncvb will be suppressed during > this calculation. >> > > Can anyone help me to solve that problem. Any help would be very much > appreciated. > Thanks in advance > Sukhrob >
From: Andrew Moylan on 14 May 2010 08:28
By default NIntegrate seeks a result with a sufficiently small *relative* error (PrecisionGoal). Some of your integrals have 0 as the true integral, for which relative error is not meaningful. NIntegrate repeatedly subdivides but never obtains an error estimate sufficiently small compared with the integral estimate. It is similar to this example: In[9]:= NIntegrate[0, {x, 0, 1}] During evaluation of In[9]:= NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in x near {x} = {0.666031}. NIntegrate obtained 0.` and 0.` for the integral and error estimates. >> Out[9]= 0. In cases where the correct value of your integral might be 0, you should set the AccuracyGoal option, which specifies an acceptable *absolute* error (independent of the size of the integral). AccuracyGoal -> 6 specifies that 10^-6 is an acceptably small absolute error. In[12]:= NIntegrate[0, {x, 0, 1}, AccuracyGoal -> 6] Out[12]= 0. I suggest Adding AccuracyGoal -> 10 to your example. As Bob Hanlon suggested, you can also use Chop[...] to tidy up the numerical results. Andrew Moylan Wolfram Research On 4/14/2010 7:16 PM, sukhrob wrote: > Hi everybody, > I'm using Mathematica 7.0 , i would like integrate numerically something > like Fourier coefficients, my programe code contains: > > M = 50; f[t_] = 100 Sin[5 t]; > > basis = Table[Sin[n t], {n, 1, M}]; > > coef = 2/Pi*Table[NIntegrate[f[t] Sin[n t], {t, 0, Pi}], {n, 1, M}] > > in result it gives : > > NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after > 9 recursive bisections in t near {t} = {2.47283}. NIntegrate obtained > -3.88578*10^-15 and 7.654706546923104`*^-15 for the integral and error > estimates.>> > NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after > 9 recursive bisections in t near {t} = {2.47283}. NIntegrate obtained > -3.19189*10^-15 and 1.8799124112361456`*^-14 for the integral and error > estimates.>> > > NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after > 9 recursive bisections in t near {t} = {0.00254055}. NIntegrate obtained > 1.2045919817182948`*^-14 and 9.105942246869344`*^-13 for the integral and > error estimates.>> > > General::stop: Further output of NIntegrate::ncvb will be suppressed during > this calculation.>> > > Can anyone help me to solve that problem. Any help would be very much > appreciated. > Thanks in advance > Sukhrob > |