Errors In Mathematica

  • Mathematica
  • Thread starter EngWiPy
  • Start date
  • #1
1,367
61

Main Question or Discussion Point

Hello,

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:
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.
 

Answers and Replies

  • #2
chroot
Staff Emeritus
Science Advisor
Gold Member
10,226
34
It tells you that the errors were generated by input In[359]. You should be able to find this in the notebook.

- Warren
 
  • #3
152
0
Is there any way to know where exactly are the errors occurred in Mathematica?
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.
 
  • #4
1,367
61
...
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.
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:
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
 
  • #5
29,570
5,890
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.
 
  • #6
1,367
61
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.
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
 
  • #7
Hepth
Gold Member
448
39
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]]
Refine[Factorial[ve]]
Refine[Factorial[-ve]]
OUTPUT:
Gamma[1 + ve]
ComplexInfinity
ve!
(-ve)!


Even though its the definition...
 

Related Threads on Errors In Mathematica

Replies
13
Views
10K
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
23
Views
4K
Replies
3
Views
3K
  • Last Post
2
Replies
34
Views
2K
Replies
2
Views
4K
Replies
4
Views
5K
Top