2
$\begingroup$

A few days ago I asked about a problem with plotting a sum. You advise me to use Evaluate option, and that helped me very. But now I have a very similar problem, but i can't find the mistake. I have a equation: $$\sum_{i=0}^x {x\choose l}\cdot l^{10}\cdot(-1)^{(x-l)}$$ I want to draw this for $$x \in [0,10]$$ I used this command:

Plot[Evaluate[Sum[Binomial[x, l]*l^50*(-1)^(x - l), {l, 0, x}]], {x, 1,2}]

There are no errors, but also no graph. If I will expand the equation for $x=1$ I have: $${1\choose 0 }\cdot 0^{10}\cdot (-1)^{1-0} + {1 \choose 1}\cdot 1^{10}\cdot (-1)^{1-1} = 1$$

and for example for $x=5$ it is: $${5\choose 0 }\cdot 0^{10}\cdot (-1)^{5-0} + {5 \choose 1}\cdot 1^{10}\cdot (-1)^{5-1} + {5\choose 2 }\cdot 2^{10}\cdot (-1)^{5-2} + {5 \choose 3}\cdot 3^{10}\cdot (-1)^{5-3} + {5\choose 4 }\cdot 4^{10}\cdot (-1)^{5-4} + {5\choose 5 }\cdot 5^{10}\cdot (-1)^{5-5} = 5 103 000$$

So as you can see, there equation can be evaluated, so why I can't see any plotted points?

$\endgroup$
2
  • $\begingroup$ You have terms like (-1)^(-0.5) which is a complex number. You need to restrict x to integers, or take the Abs[ ] or plot over a range where you don't get complex-valued numbers. $\endgroup$
    – bill s
    Dec 6, 2013 at 1:31
  • $\begingroup$ @bill Is any other way to restrict x to integers than DiscretePlot? $\endgroup$
    – Ziva
    Dec 6, 2013 at 1:46

2 Answers 2

2
$\begingroup$

Revised version

It seems you don't want to use Plot, because this creates a continuous plot in the region. You want to draw the sum for integer values of x. It takes a good amount of time, but your sum can be evaluated analytically

s = Sum[Binomial[x, l]*l^50*(-1)^(x - l), {l, 0, x}]

(* (-(-1)^x)*x*
 HypergeometricPFQ[{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1 - x}, 
     {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
       1, 1, 1, 1, 1, 1, 1}, 1] *)

and now you can create the data you like

Table[s, {x, 1, 5}]

(* {1, 1125899906842622, 717897984314152868242380, \
1267647728636285389485789180120, 88811503724190361952542576750515000} *)

or plot it using ListPlot or ListLinePlot (I use Log here, because the values increase very fast)

ListLinePlot[Log[Table[s, {x, 1, 10}]]]

Mathematica graphics

$\endgroup$
5
  • $\begingroup$ Do I correctly understand that in the solution which you suggested this sum is evaluated from l=0 to 1 when x=1 and again from l=0 to 2 when x=2? And does 'Re@' mean repeat? $\endgroup$
    – Ziva
    Dec 6, 2013 at 1:50
  • $\begingroup$ First mistake which I made was that I didn't restriced x to integers. $\endgroup$
    – Ziva
    Dec 6, 2013 at 1:53
  • $\begingroup$ @Ziva, right, it was not obvious from your question that you only want integers for x. Plot samples the region between 1 and 2 very fine and the sum is evaluated for x=1, 1.00001, 1.00002, ... which looks wrong. If you only want integer solutions, the Plot is not the way to go. $\endgroup$
    – halirutan
    Dec 6, 2013 at 1:55
  • $\begingroup$ @Ziva Let me update my answer. $\endgroup$
    – halirutan
    Dec 6, 2013 at 1:56
  • $\begingroup$ Thank you for your help. I have one more question for this a = 21 s = Sum[Binomial[x, j]*j^a*(-1)^(x - j), {j, 0, x}] Table[s, {x, 1, 2}] this is working wrong, because it count that for x = 1 s=-10 905180. For a=23 or a =11 it works good. Why for a=21 it is working wrong? $\endgroup$
    – Ziva
    Dec 6, 2013 at 16:57
1
$\begingroup$

I am confused by the test which has exponent 10 and the code which has exponent 50 so have dealt with both:

f[x_, n_] := Total[Binomial[x, #] #^n (-1)^(x - #) & /@ Range[0, x]]

Visualizing:

GraphicsRow[
 ListLogPlot[Table[f[x, #], {x, 1, 5}], Filling -> Axis, 
    PlotStyle -> {Red, PointSize[0.02]}, FillingStyle -> Thick, 
    AxesOrigin -> {0, 1}, 
    PlotLabel -> 
     Row[{"n=", #}, BaseStyle -> {FontFamily -> "Calibri", 16}], 
    ImageSize -> 300] & /@ {10, 50}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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