Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I have the following series:

f[x_] := Sin[x]
n := 50

Ni3[x_] := Sum[(f[k]*(-1)^k)/((x - k)*Gamma[k + 1]*Gamma[n - k + 1]), {k, 0, n}]/
           Sum[(-1)^k/((x - k)*Gamma[k + 1]*Gamma[n - k + 1]), {k, 0, n}]

Plot[{Ni3[x], f[x]}, {x, -7, 7}, AspectRatio -> Automatic, PlotRange -> 10]

At number of terms n below 40 the plot gives what is expected. But when increasing it above 50 the plot becomes corrupted. The setting $MinPrecision does not affect the result. The series is proven to converge to $f(x)=\sin(x)$.

bad plot

share|improve this question

marked as duplicate by Mr.Wizard Jul 19 '13 at 0:34

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Try using a high value of WorkingPrecision in Plot, e.g. WorkingPrecision -> 60. – Szabolcs May 7 '13 at 3:42
@Szabolcs you made incorrect change to the expression, putting one sum inside the other – Anixx May 7 '13 at 3:44
@Szabolcs re Working Precision - thanks, it worked. – Anixx May 7 '13 at 3:46
Sorry about that. When you paste expressions like this, select them, right click, then use Copy As -> Input Form. – Szabolcs May 7 '13 at 3:47
@Szabolcs I did exactly that. It is what exported as Input Form. – Anixx May 7 '13 at 3:48
up vote 3 down vote accepted

As Szabolcs suggests, cranking up WorkingPrecision (or for that matter, just forcing Plot[] to use arbitrary precision) helps a lot. In this answer, I've taken the liberty to slightly simplify your barycentric interpolant as well:

f[x_] := Sin[x]

Ni3[n_Integer, x_] := (x - n) Binomial[x, n]
    Sum[(-1)^(n - k) Binomial[n, k] f[k]/(x - k), {k, 0, n}, Method -> "Procedural"]

Plot[{Ni3[50, x], f[x]}, {x, -7, 7}, AspectRatio -> Automatic, 
     PlotRange -> 10, WorkingPrecision -> 20]

sine and barycentric interpolant

share|improve this answer
How to force it to use arbitrary precision? – Anixx May 7 '13 at 3:50
You get this plot with WorkingPrecision -> 20? I get junk with that ... I needed a much higher value. – Szabolcs May 7 '13 at 3:50
@Szabolcs, well, I simplified OP's function a bit; that helped. – J. M. May 7 '13 at 3:51
@Anixx, as I said, with WorkingPrecision. – J. M. May 7 '13 at 3:52
To be precise, it runs out of precision around 1.5 for a precision setting of 20, around -1.2 for 30, and looks fine for 40 (for default plot range). – Szabolcs May 7 '13 at 3:52

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