# How can I avoid the message Infinity::indet?

I have an impulse train of frequency R:

1/(R + 1) + (Sum[Cos[(2 k π x)/(R + 1)], {k, R}])/(R + 1)


For x = 0, the function is equal to 1 regardless of the value of R. This is because

Cos[(2 k π x)/(R + 1)] /. x -> 0 == Cos[0] == 1


and

1/(R + 1) + (Sum[1, {k, R}])/(R + 1) == 1/(R + 1) + R/(R + 1) ==
(R + 1)/(R + 1) == 1


Mathematica disagrees with me. The command

Evaluate[1/(R + 1) + (Sum[Cos[(2 k π x)/(R + 1)], {k, R}])/(R + 1) /. x -> 0]


produces the message

Infinity::indet: Indeterminate expression 0 ComplexInfinity encountered.

This is clearly wrong. Can anyone suggest how I work around it?

• It's an indeterminate form (and this is exactly what the substitution indicates). So one should take a limit: In[8]:= Limit[ 1/(R + 1) + (Sum[Cos[(2 k \[Pi] x)/(R + 1)], {k, R}])/(R + 1), x -> 0] Out[8]= 1 – Daniel Lichtblau Jul 21 '18 at 14:53
• Will the Limit suggestion work with plots and the like? – Richard Burke-Ward Jul 21 '18 at 15:12
• I should rephrase that. How do I make this work with Plot? I want to graph the product of this function and another function, but without the discontinuities. – Richard Burke-Ward Jul 21 '18 at 16:08
• Please provide the full example that gives you the headaches. A simple plot works. It's not clear what is the capital X, and what value for the R you are substituting, and what kind of Plot you do. – kkm Jul 21 '18 at 21:33
• Can you please just update the question, so that it shows an expression I can evaluate and see the error? It is much easier to help you this way. Also, it is still unclear what problem you are solving. The function can be plotted just fine. f[R_, x_] = ((2 x)/(x^2 + 1)^2) ((1/(R + 1) + (Sum[ Cos[(2 k \[Pi] x)/(R + 1)], {k, R}])/(R + 1))); Plot[f[20, x], {x, -2, 2}]. The repairable discontinuity at $x/(R+1)\in\mathbb{Z}$ seems like an artifact of the method, and Plot can deal with it. – kkm Jul 21 '18 at 23:27

Write the Sin and Csc functions in terms of the Sinc function.

Clear[f]

f[x_, R_] = ((2 x/(x^2 + 1)^2) ((1/(R + 1) + (Sum[
Cos[(2 k π x)/(R + 1)], {k, R}])/(R + 1))) //
FullSimplify) /. {Sin[z_] :> z*Sinc[z], Csc[z_] :> 1/(z*Sinc[z])} //
Simplify

(* (x + ((1 + 2 R) x Sinc[(π (1 + 2 R) x)/(1 + R)])/
Sinc[(π x)/(1 + R)])/((1 + R) (1 + x^2)^2) *)

f[0, R]

(* 0 *)

Plot3D[f[x, R], {x, -3, 3}, {R, 0, 5},
ClippingStyle -> None,
PlotPoints -> 50,
MaxRecursion -> 6]


Expanding the PlotRange

Plot3D[f[x, R], {x, -3, 3}, {R, 0, 5},
ClippingStyle -> None,
PlotPoints -> 50,
MaxRecursion -> 6,
PlotRange -> {-1, 1}]


You can also write your function in Piecewise form.

Limit[1/(R + 1) + Sum[Cos[(2*k*Pi*x)/(R + 1)], {k, R}]/(R + 1), x -> 0]
(*1*)

fn1 = Piecewise[{{1, x == 0}},
1/(R + 1) + (Sum[Cos[(2 k \[Pi] x)/(R + 1)], {k, R}])/(R + 1)] // Simplify;

fn2 = (2 x)/(x^2 + 1)^2;

fn[x_, R_] = fn1 fn2;


You can then plot fn[x,R]` with no indeterminant problems.