3
$\begingroup$

How can I find all the values of a variable at which a given expression diverges or becomes undefined?

Example:

expr=1/(1-x^2);

Desired result:

(* {1,-1} or {{x->1},{x->-1}} *)

Example:

expr=x/x

Desired result:

(* 0  or {0}  or {{x->0}} *) 

EDIT: Some users pointed out I can just find when the Denominator[expr]==0, but that doesn't work for some functions like:

expr=Exp[1/x]
$\endgroup$
2
  • $\begingroup$ How about Solve[0 == 1/expr, x]. That will at least get you the ones where it diverges. $\endgroup$
    – march
    Commented Dec 8, 2015 at 21:15
  • $\begingroup$ @march That doesn't work for more complicated stuff like expr=Exp[1/x] $\endgroup$ Commented Dec 9, 2015 at 13:45

2 Answers 2

3
$\begingroup$

Update 1

The following function works for all the cases mentioned so far except for the trivial x/x case.

 findPoles[expr_] := Module[{pos, npos},
 (*find position of all Power in the fullform of the function*)
 pos = Position[FullForm[expr], Power];
 (*drop the last 0 to get the position of the actual power
 expression*)
 npos = Drop[pos[[#]], -1] & /@ Range[Length[pos]];
 (*extract those position, 
 find their denominators and delete those which have none. 
 Lastly Solve for the poles*)
 Solve[DeleteCases[Denominator[Extract[FullForm[expr], npos]], 1] == 
    0, x]]

Testing the function

 expr[1] = 1/(1 - x^2);
 expr[2] = Exp[1/x];
 Table[findPoles[expr[i]], {i, 2}]
 (*{{{x -> -1}, {x -> 1}}, {{x -> 0}}}*)

Using the Denominator command and then Solve

findDiv[exp_] := 
Which[exp === 1, {{x -> 0}}, True, Solve[Denominator[exp] == 0, x]]

expr = 1/(1 - x^2);
findDiv[expr]
(*{{x\[Rule]-1},{x\[Rule]1}}*)

expr = x/x;
findDiv[expr]
(*{{x\[Rule]0}}*)
$\endgroup$
4
  • $\begingroup$ Thanks! But I why did you put it inside a Which[]? And why do you have it return x->0 if the input expression is identical to 1? $\endgroup$ Commented Dec 8, 2015 at 21:20
  • $\begingroup$ well that was just to reproduce the desired result for your second example where x/x evaluates to 1 $\endgroup$
    – Hubble07
    Commented Dec 9, 2015 at 6:47
  • $\begingroup$ This doesn't work for more complicated stuff like expr=Exp[1/x] $\endgroup$ Commented Dec 9, 2015 at 13:47
  • $\begingroup$ @JerryGuern check the updated answer $\endgroup$
    – Hubble07
    Commented Dec 9, 2015 at 15:32
2
$\begingroup$
expr = 1/(1 - x^2);

FunctionDomain[expr, x]

enter image description here

Plot[expr, {x, -2, 2}]

enter image description here

Show "complement" graphically

NumberLinePlot[
 expr == 10^6,
 {x, -2, 2},
 AspectRatio -> 1/3,
 Frame -> True,
 FrameTicks -> {Automatic, None, None, None},
 GridLines -> {Automatic, None},
 GridLinesStyle -> Directive[Gray],
 PlotStyle -> PointSize[Large],
 PlotTheme -> "Detailed"]

enter image description here

$\endgroup$
1
  • $\begingroup$ Interesting info, but I want what we might call the "compliment of the domain", not the domain. $\endgroup$ Commented Dec 8, 2015 at 21:22

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.