ComplexInfinity encountered in Mathematica

  • Context: Mathematica 
  • Thread starter Thread starter EngWiPy
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary

Discussion Overview

The discussion revolves around a Mathematica code segment that produces an error related to ComplexInfinity. Participants explore the implications of the Gamma function and the conditions under which the error occurs, focusing on the mathematical definitions and programming logic needed to resolve the issue.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant shares a code snippet and describes the error message encountered when running it, specifically mentioning the occurrence of ComplexInfinity.
  • Another participant identifies that the error may arise from the Gamma function evaluating to Gamma[0], which is undefined.
  • There is a suggestion to include an If statement in the code to handle the case where Gamma[0] is invoked, but the validity of this approach is questioned.
  • One participant reflects on their past experiences with similar issues, suggesting that calculating limits manually or using If statements can be a workaround for undefined expressions.
  • Another participant discusses the need to ensure the domain of certain expressions is correctly defined to avoid invalid calculations, relating this to their specific application in computing the Moment Generating Function (MGF) for Symbol Error Rate in wireless communication.
  • Concerns are raised about the potential for negative outputs after implementing changes, which would be inconsistent with the expected range of the Symbol Error Rate.

Areas of Agreement / Disagreement

Participants express varying opinions on the best approach to resolve the error, with some supporting the use of conditional statements while others remain uncertain about their effectiveness. The discussion does not reach a consensus on a definitive solution.

Contextual Notes

Participants note that the problem may involve complex limits and undefined expressions, and there is uncertainty regarding the correct handling of these cases in the code.

Who May Find This Useful

This discussion may be useful for individuals working with Mathematica, particularly those encountering issues with the Gamma function or dealing with complex mathematical expressions in programming contexts.

EngWiPy
Messages
1,361
Reaction score
61
Hello,

I have the following segement of code:

Code:
IA1[N_, k_, n_, sig_, al_] := (
   Sqrt[Pi]*(4*al)^(n + 1))/(sig - s + (2*al))^(NA + k + n + 1)*(
   Gamma[N + k + n + 1]*Gamma[N + k - n - 1])/Gamma[N + k + 0.5]*
   Hypergeometric2F1[N + k + n + 1, n + 1.5, N + k + 0.5, (
    sig - s - 2*al)/(sig - s + 2*al)];
IA2[N_, k_, n_, sig_, al_] := (Sqrt[Pi]*(4*al)^n)/(sig - s + (2*al))^(
   NA + k + n + 1)*(Gamma[N + k + n + 1]*Gamma[N + k - n + 1])/
   Gamma[N + k + 1.5]*
   Hypergeometric2F1[N + k + n + 1, n + 0.5, N + k + 1.5, (
    sig - s - 2*al)/(sig - s + 2*al)];
IA[N_, k_, n_, sig_, al_] := 
  2*(N + k - n - 1)*IA1[N, k, n, sig, al] - 
   sig*D[IA1[N, k, n, sig, al], s] - 2*al*IA2[N, k, n, sig, al];

and when I run it, the following error appears:

Code:
\[Infinity]::indet: Indeterminate expression 0 ComplexInfinity \
encountered. >>

\[Infinity]::indet: Indeterminate expression 0 ComplexInfinity \
encountered. >>

\[Infinity]::indet: Indeterminate expression 0 ComplexInfinity \
encountered. >>

But I didn't find a situation where we can get ComplexInfinity. Can anyone help me, please?

Note: the minimum value for N=1, K=0, n=0, and sig and al are essentially greater than zero
 
Last edited:
Physics news on Phys.org
Hi S_David,

S_David said:
Hello,

I have the following segement of code:

Code:
IA1[N_, k_, n_, sig_, al_] := (
   Sqrt[Pi]*(4*al)^(n + 1))/(sig - s + (2*al))^(NA + k + n + 1)*(
   Gamma[N + k + n + 1]*Gamma[N + k - n - 1])/Gamma[N + k + 0.5]*
   Hypergeometric2F1[N + k + n + 1, n + 1.5, N + k + 0.5, (
    sig - s - 2*al)/(sig - s + 2*al)];
IA2[N_, k_, n_, sig_, al_] := (Sqrt[Pi]*(4*al)^n)/(sig - s + (2*al))^(
   NA + k + n + 1)*(Gamma[N + k + n + 1]*Gamma[N + k - n + 1])/
   Gamma[N + k + 1.5]*
   Hypergeometric2F1[N + k + n + 1, n + 0.5, N + k + 1.5, (
    sig - s - 2*al)/(sig - s + 2*al)];
IA[N_, k_, n_, sig_, al_] := 
  2*(N + k - n - 1)*IA1[N, k, n, sig, al] - 
   sig*D[IA1[N, k, n, sig, al], s] - 2*al*IA2[N, k, n, sig, al];

and when I run it, the following error appears:

Code:
\[Infinity]::indet: Indeterminate expression 0 ComplexInfinity \
encountered. >>

\[Infinity]::indet: Indeterminate expression 0 ComplexInfinity \
encountered. >>

\[Infinity]::indet: Indeterminate expression 0 ComplexInfinity \
encountered. >>

But I didn't find a situation where we can get ComplexInfinity. Can anyone help me, please?

Note: the minimum value for N=1, K=0, n=0, and sig and al are essentially greater than zero

Inside IA1 you have:

Code:
Gamma[N+k-n-1]

which for the values you are using becomes Gamma[0].
 
Wow, you are absolutely right. I didn't know that Gamma[0] is undefined, too. I thought just for the negative values. In this case we must include an If[] statement for the code to work. Is this a valid step?

Ok, thanks a lot alphysicist, and wish you luck.

Best Regards
 
S_David said:
Wow, you are absolutely right. I didn't know that Gamma[0] is undefined, too. I thought just for the negative values. In this case we must include an If[] statement for the code to work. Is this a valid step?

Ok, thanks a lot alphysicist, and wish you luck.

Best Regards

Sure, glad to help!

I'm not sure what you are calculating, so I can't say that an If statement is the right thing to do. I can't see that there is anything wrong with it, though. I have done calculations in the past that blew up at the origin and just did a quick If branch to get through it.
 
alphysicist said:
Sure, glad to help!

I'm not sure what you are calculating, so I can't say that an If statement is the right thing to do. I can't see that there is anything wrong with it, though. I have done calculations in the past that blew up at the origin and just did a quick If branch to get through it.

If we have the following expression f(x)=\frac{1}{\sqrt{x}}, then the domain must be x>0, because for other values the function doen't exist in the real axis. I think we can say the same in my problem, because there is no other way to overcome the problem. I am computing the Moment Generating Function (MGF) to compute the Symbol Error Rate in a wireless communication system.

Thanks.
 
S_David said:
If we have the following expression f(x)=\frac{1}{\sqrt{x}}, then the domain must be x>0, because for other values the function doen't exist in the real axis. I think we can say the same in my problem, because there is no other way to overcome the problem. I am computing the Moment Generating Function (MGF) to compute the Symbol Error Rate in a wireless communication system.

Thanks.

Here's what I essentially did the last time I ran into this type of problem. The problem was essentially along the lines of:

<br /> f(x)=\frac{1-e^{-x}}{x}<br />

which has a finite limit at x=0, but the computer does not want to divide by zero. So I just calculated the limit by hand and put it in an If statement.

However, I did that just because it was straightforward. Your problem looks more difficult, so maybe you would want to see if mathematica can calculate the limit, if that's what needed? Or do you already know the value, or can you just skip that value altogether? Those considerations will tell you the right approach.
 
alphysicist said:
Here's what I essentially did the last time I ran into this type of problem. The problem was essentially along the lines of:

<br /> f(x)=\frac{1-e^{-x}}{x}<br />

which has a finite limit at x=0, but the computer does not want to divide by zero. So I just calculated the limit by hand and put it in an If statement.

However, I did that just because it was straightforward. Your problem looks more difficult, so maybe you would want to see if mathematica can calculate the limit, if that's what needed? Or do you already know the value, or can you just skip that value altogether? Those considerations will tell you the right approach.

After double check, the term (N+k-n-1)\ge 0, because the maximum value of n is N+k-1. I tried to write the limit as n\longrightarrow N+k-1 but Mathematica didn't compute it, and gives ComplexInfinity again. I am not sure if I can calculate it manually, it seems complicated.

I don't know where, but I am sure that I have something wrong, because when I run the program, after writting the If statement, I got negative answers, which must not occur in my case, because the SER is in the range of [0,1] by definition.

Best regards
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
7K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 3 ·
Replies
3
Views
2K