3
$\begingroup$

Hi mathematica people!

So i am looking for the best way to interpolate a function given a list of its values. I have an iterative algorithm which needs high precision otherwise the numerical noise is going to increase exponentially. It works like this(not the exact code, but just to illustrate):

Nmax := 10;
Tmax := 1000;
K[t_, s_] := s^2 (PolyGamma[2, 1 - (t-s)] - 0.5 PolyGamma[2, 1 - (t-s)/2])

Table[{t, NIntegrate[ K[t,s] (PolyGamma[1, 1 - 2 I s] - 0.5 PolyGamma[1, 1 - I s]) ,{s, 0, t-1} ]}, {t, 1, Tmax} ]
f[0]:= Interpolation[ %, InterpolationOrder -> 1 ];

For[ i = 1 , i < Nmax , i++ , 
Table[{t, NIntegrate[ K[t,s] f[i][s] ,{s, 0, t-1} ]}, {t, 1, Tmax} ];
f[i+1] := Interpolation[ %, InterpolationOrder -> 1 ]; 
]

The problem with this is that each function f[i] is coming from integrating f[i-1], so errors are going to be multiplied and enhanced. Is there a better way to integrate numerical interpolation? Or perhaps a better way to interpolate?

In the end i am interested in obtaining a plot of

f := Sum[ f[i] , {i , 0 , Nmax } ]
$\endgroup$
  • $\begingroup$ Thanks, this was helpful :) With Method -> InterpolationPointsSubdivision i could avoid the convergence failure error. $\endgroup$ – Libero.ego Nov 25 '14 at 23:09
1
$\begingroup$

Some points:

  1. You are integrating a function of InterpolatingFunction. See this thread for guidance how to achieve maximum precision in this situation using NIntegrate.

  2. You are using Sum for summing up imprecise numbers which is the worst way to do this as demonstrated here. Use Total with option "CompensatedSummation" -> True instead.

  3. Avoid using explicit loops and use functional programming instead. This point is discussed in details in many places on this site. In particular, I recommend reading these threads:

    What are the most common pitfalls awaiting new users?

    Where can I find examples of good Mathematica programming practice?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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