Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Errors In Mathematica

  1. Jul 1, 2009 #1

    Is there any way to know where exactly are the errors occurred in Mathematica? For example, I have the following error in my long code:

    Code (Text):
    During evaluation of In[359]:= \[Infinity]::indet: Indeterminate \
    expression 0 ComplexInfinity encountered. >>

    During evaluation of In[359]:= \[Infinity]::indet: Indeterminate \
    expression 0 ComplexInfinity encountered. >>

    During evaluation of In[359]:= \[Infinity]::indet: Indeterminate \
    expression 0 ComplexInfinity encountered. >>

    During evaluation of In[359]:= General::stop: Further output of \
    \[Infinity]::indet will be suppressed during this calculation. >>

    Out[381]= $Aborted
    but I don't know where exactly the error is.

    Thanks in advance.
  2. jcsd
  3. Jul 1, 2009 #2


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    It tells you that the errors were generated by input In[359]. You should be able to find this in the notebook.

    - Warren
  4. Jul 1, 2009 #3
    The short answer is yes, there are a large number of tools and strategies for debugging Mathematica code.

    The most simple method, which is also the one I use 99% of the time and recommend most highly as a Mathematica expert, is to take advantage of the interpreted nature of the language by building a larger computation out of smaller pieces that you have already debugged.

    Another primitive but effective debugging strategy is to include Print[] statements in the middle of your calculation, to see that your variables have the values you expect.

    Some more formal debugging tools are Trace[] and Monitor[]. Trace[expr] will output a list of the intermediate expressions used in the computation of expr. Monitor[n] will output a list of the values taken by the variable n.

    If you want, post your code and I will be happy to find and fix the error and/or suggest some tips. Nowadays I use Mathematica all day long with out generating any errors, it's truly beautiful --- but I remember the old days when even the simplest expressions would take me hours of debugging.
  5. Jul 1, 2009 #4
    Actually, I am new on Mathematica, and as you said about yours old days, it takes me a considerable amount of time to find a small error, if I found it. Anyway, after some effort, I narrowed the piece of code that contains the error in the following:

    Code (Text):
    f1[ze_, al_] := 1/2*(ze - s - Sqrt[(ze - s)^2 - 4*al^2]);
    f2[ze_, al_] := 1/2*(ze - s + Sqrt[(ze - s)^2 - 4*al^2]);
    G[b_, f1_, f2_] := (
      HypergeometricU[1, 1 - b, f1] - HypergeometricU[1, 1 - b, f2])/(
      2*(f2 - f1));
    Xe[ze_, al_, E_, x_] := ((2*(x)!)/al^x \!\(
    \*UnderoverscriptBox[\(\[Sum]\), \(z = 0\), \(x\)]Binomial[x,
            z]*\((E*D[G[x, f1[ze, al], f2[ze, al]], {s, E - 1 + z}] -
             ze*D[G[x, f1[ze, al], f2[ze, al]], {s, E + z}])\)\)) - ((
         2*al*(x - 1)!)/al^(x - 1) \!\(
    \*UnderoverscriptBox[\(\[Sum]\), \(z = 0\), \(x - 1\)]Binomial[x - 1,
            z]*\((2*D[G[x - 1, f1[ze, al], f2[ze, al]], {s, E + z + 1}] +
             D[G[x - 1, f1[ze, al], f2[ze, al]], {s, E + z}])\)\));

    In[12]:= Xe[0.05, 0.1, 0, 0]

    During evaluation of In[12]:= \[Infinity]::indet: Indeterminate \
    expression 0 ComplexInfinity encountered. >>

    Out[12]= Indeterminate
    Please, copy the code from here, and paste it at your Mathematica editor, because some symbols, powers and square roots are translated into other forms.

    Thank you for your replying Civilized and chroot.

    Best regards
  6. Jul 2, 2009 #5


    Staff: Mentor

    In your function Xe, in the second term the first part:
    ( 2*al*(x - 1)!)/al^(x - 1)
    evaluates to ComplexInfinity

    Meanwhile the second part:
    \*UnderoverscriptBox[\(\[Sum]\), \(z = 0\), \(x - 1\)]\(Binomial[
    x - 1, z]*\((2*
    D[G[x - 1, f1[ze, al], f2[ze, al]], {s, E + z + 1}] +
    D[G[x - 1, f1[ze, al], f2[ze, al]], {s, E + z}])\)\)\)
    evaluates to 0.

    Infinity times 0 is undefined, so you get the error you are having.

    By the way, the reason the first part evaluates to ComplexInfinity is that your argument x is 0 and so (x-1)! means that you are taking the factorial of a negative number. Probably you don't want to do that, so most likely x should always be greater than or equal to 1.
  7. Jul 2, 2009 #6
    Really? but when you write at a Mathemtica editor Factorial[-ve] it dosen't give you ComplexInfinity, but 0 as I know,so , I left it as is!! Although your observation may be in its place about that [tex]x\ge 1[/tex].

    Thank you very much DaleSpam, I will try this and I hope it will solve the problem.
    Best regards
  8. Jul 3, 2009 #7


    User Avatar
    Gold Member

    because Factorial[-ve] IS defined for non-integer values of "ve".

    Plot[n!, {n, -2.5, 3}]

    But what I dont like is that even if you make the assumption that ve belongs to integers, it wont take it as complex infinity. BUT the gamma will:

    $Assumptions =
    ve \[Element] Reals && ve > 1 && ve \[Element] Integers;
    Refine[Gamma[ve + 1]]
    Refine[Gamma[-ve + 1]]
    Gamma[1 + ve]

    Even though its the definition...
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: Errors In Mathematica
  1. Mathematica Error (Replies: 4)

  2. Mathematica error (Replies: 23)