# Exclude Infinite Value in Table

I'm creating a plot of a family of lines using their endpoints and plotting it like so:

Graphics[Line[Table[{{x1, y1}, {x2, y2}}, {u, 0, 2 \[Pi], ustep}]]]


Where x1, y1, x2 and y2 have previously been defined in terms of u. The problem is that it is possible for this definition to produce an infinite result for a single pair of x and y. When this infinity is encountered, Mathematica complains and none of the lines are actually displayed. I'd like Mathematica to just glaze over the invalid one and display all the rest.

More details:

• There is a condition on u which could be used to find the problem point. (Let's just say $f(u) = 0$ for simplicity and generality.)
• I don't explicitly know a priori where this undefined value will occur in the table (or even that it will be present at all).

Is there any way to tell Mathematica to skip Table values based on some rule?

• There is; it is called Pattern matching – Sektor Oct 22 '14 at 4:48
• I don't understand where/why you get infinity. Can you provide a small numerical example where this happens? I think that would help in order to give you a good answer. – mickep Oct 22 '14 at 5:10
• @mickep Take for example x1 = 1/u. When u=0, x1 is infinite. – Roger Burt Oct 22 '14 at 5:15
• Is there any way to tell Mathematica to skip Table values based on some rule? how about DeleteCases ? Example: DeleteCases[{1, 2, Infinity, 3, 4}, Infinity] gives {1, 2, 3, 4} or DeleteCases[{1, 2, Infinity, 3, 4, 1/0}, Infinity | ComplexInfinity] – Nasser Oct 22 '14 at 5:33
• Unfortunately, that doesn't work when the elements of the list are themselves lists. e.g. DeleteCases[{1, {2, Infinity}, 3,{ 4, 1/0}}, Infinity | ComplexInfinity] – Roger Burt Oct 22 '14 at 5:48

I suppose you have something like this:

expr = Table[{{1/u, u^2}, {Sqrt[u], 1/Sin[u]}}, {u, 0, 2 Pi, Pi/4}]

{{{ComplexInfinity, 0}, {0, ComplexInfinity}}, {{4/π, π^2/16}, {Sqrt[π]/2,
Sqrt}}, {{2/π, π^2/4}, {Sqrt[π/2], 1}}, {{4/(3 π), (9 π^2)/
16}, {Sqrt[3 π]/2, Sqrt}}, {{1/π, π^2}, {Sqrt[π],
ComplexInfinity}}, {{4/(5 π), (25 π^2)/16}, {Sqrt[5 π]/2, -Sqrt}}, {{2/(
3 π), (9 π^2)/4}, {Sqrt[(3 π)/2], -1}}, {{4/(7 π), (49 π^2)/
16}, {Sqrt[7 π]/2, -Sqrt}}, {{1/(2 π), 4 π^2}, {Sqrt[2 π],
ComplexInfinity}}}


And you want to remove the results that include ComplexInfinity. Then consider these:

Cases[expr, {{__?NumericQ} ..}]

Select[expr, MatrixQ[#, NumericQ] &]

Select[expr, FreeQ[#, ComplexInfinity] &]


Other ways to write the last one, assuming version 10 or later:

Select[expr, FreeQ[ComplexInfinity]]

expr ~Select~ FreeQ[ComplexInfinity]

expr // Select @ FreeQ @ ComplexInfinity