Equation Evaluation Problem in Mathematica

  • Mathematica
  • Thread starter EngWiPy
  • Start date
  • Tags
    Mathematica
In summary, the conversation is about a Mathematica code and its output being the same for different values of SNR. The participants discuss the defined constants A, Q, and Ne and the function Meq. They also mention the need to clear variables and restarting the kernel. The conversation ends with a discussion on how to fix the code to get different outputs for different values of SNR.
  • #1
EngWiPy
1,368
61
Hello,

I have the following line in Mathematica:

Code:
Print[Pout = (2^-Q*E^(A/2))/SNR \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(q = 0\), \(Q\)]Binomial[Q, q] \(
\*UnderoverscriptBox[\(\[Sum]\), \(n = 0\), \(Ne + q\)]
FractionBox[
SuperscriptBox[\((\(-1\))\), \(n\)], \(a[n]\)] Re[
\*FractionBox[\(Meq[\(-
\*FractionBox[\(A + \((2*Pi*I*n)\)\), \(2*SNR\)]\)]\), 
FractionBox[\(A + \((2*Pi*I*n)\)\), \(2*SNR\)]]]\)\)]

But the problem is that for different values of SNR, the result will be the same all the time. Why is that happening? A, Q, and Ne are all constants.

Thanks in advance
 
Physics news on Phys.org
  • #2
What are some examples of what A Q and Ne are so i can try it?
and what is meq?
 
  • #3
Hepth said:
What are some examples of what A Q and Ne are so i can try it?
and what is meq?

Try these expressions:
Code:
A=23
Q=15
Ne=21
Meq[s_]:=1/(1-s)

Regards
 
  • #4
and also, the a[n] function or array?

but before that make sure youre clearing any variables youre reusing.
restarting the kernel does that.
 
  • #5
Hepth said:
and also, the a[n] function or array?

but before that make sure youre clearing any variables youre reusing.
restarting the kernel does that.

Assume
Code:
a[n]=1
How clear all variables? I have many of them.

Regards
 
  • #6
I have the same problem again in the following code:

Code:
gA = 10;
M = 1;
Ne = 1;
If[M >= 1, m = M, m = 0];
For[SNRdB = 0, SNRdB <= 10, SNRdB++,
 SNR = 10^(SNRdB/10);
 Print[F1 = \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(r = m\), \(M\)]\(
\*UnderoverscriptBox[\(\[Sum]\), \(i = 0\), \(M - r\)]\(
\*UnderoverscriptBox[\(\[Sum]\), \(j = 0\), \(r + i\)]\(
\*UnderoverscriptBox[\(\[Sum]\), \(k = 0\), \(j*\((Ne - 1)\)\)]
\*SuperscriptBox[\((\(-1\))\), \(i + j\)]*Binomial[M, r]*
        Binomial[M - r, i]*Binomial[r + i, j]*
\*SuperscriptBox[\(E\), 
FractionBox[\(\(-j\)*SNR\), \(gA\)]]*
\*SuperscriptBox[\((
\*FractionBox[\(SNR\), \(g\)])\), \(k\)]\)\)\)\)]]
For[SNRdB = 0, SNRdB <= 10, SNRdB++,
 SNR = 10^(SNRdB/10);
 Print[F2 = 1 - \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(r1 = m\), \(M - 1\)]\(
\*UnderoverscriptBox[\(\[Sum]\), \(i1 = 1\), \(M - r1\)]\(
\*UnderoverscriptBox[\(\[Sum]\), \(j1 = 1\), \(r1 + i1\)]\(
\*UnderoverscriptBox[\(\[Sum]\), \(k1 = 0\), \(j1*\((Ne - 1)\)\)]
\*SuperscriptBox[\((\(-1\))\), \(i1 + j1\)]*Binomial[M, r1]*
         Binomial[M - r1, i1]*Binomial[r1 + i1, j1]*
\*SuperscriptBox[\(E\), 
FractionBox[\(\(-j1\)*SNR\), \(gA\)]]*
\*SuperscriptBox[\((
\*FractionBox[\(SNR\), \(g\)])\), \(k1\)]\)\)\)\)]]

1-1/\[ExponentialE]^(1/10)

1-\[ExponentialE]^-1/10^(9/10)

1-\[ExponentialE]^-1/10^(4/5)

1-\[ExponentialE]^-1/10^(7/10)

1-\[ExponentialE]^-1/10^(3/5)

1-\[ExponentialE]^-1/Sqrt[10]

1-\[ExponentialE]^-1/10^(2/5)

1-\[ExponentialE]^-1/10^(3/10)

1-\[ExponentialE]^-1/10^(1/5)

1-\[ExponentialE]^-1/10^(1/10)

1-1/\[ExponentialE]

1

1

1

1

1

1

1

1

1

1

1

Why is the second part constant, even though it is a dependent on SNR?

Regards
 
  • #7
Because of your sums and their indices. To fix this, add:

If[M > 1, m = M, m = 0];

before the second For loop. It changes the greater than equal to to just a greater than. That way the second sum in the second for loop doesn't go from 1 to 0 (1 to M-r1 == M-m==0)
 
  • #8
As for your first question, I DO get something different each time I change SNR.
 
  • #9
Hepth said:
As for your first question, I DO get something different each time I change SNR.

Really? How is that? Try to put the SNR in a For[] loop, and tell me what will happen. Because I am using a For[] loop actually.

Regarding your previous post, I have doubts that I have something wrong in the mathematical equations. So, I will double check them and see what happen then.

Thank you
 
  • #10
FOR:
Code:
A = 23;
Q = 15;
Ne = 21;
Meq[s_] := 1/(1 - s)
a[n_] = 1;
For[SNRdB = 0, SNRdB <= 10, SNRdB++,
  SNR = 10^(SNRdB/10);
Print[
   Pout =
          Refine[(1.0) (2^-Q*E^(A/2))/SNR
[tex]
\left.\left.\left.\sum _{q=0}^Q \text{Binomial}[Q,q]\sum _{n=0}^{\text{Ne}+q} \frac{(-1)^n}{a[n]}\text{Re}\left[\frac{\text{Meq}\left[-\frac{A+(2*\text{Pi}*I*n)}{2*\text{SNR}}\right]}{\frac{A+(2*\text{Pi}*I*n)}{2*\text{SNR}}}\right]\right]\right]\right]
[/tex]

The changes I made were adding the Refine to simplify the complex stuff, and multiplying by 1.0 to give me a real value.
I also added the SNR changing in the for loop. Looks like it changes when SNR does. Or did I do something wrong?

EDIT: oops, here's my output:
343.991

424.207

520.658

635.431

770.336

926.63

1104.7

1303.75

1521.56

1754.43

1997.27
 
Last edited:
  • #11
S_David said:
Regarding your previous post, I have doubts that I have something wrong in the mathematical equations. So, I will double check them and see what happen then.

Thank you

What I mean is that for your given values, you have a sum over
[tex]
\sum _{\text{r1}=m}^{M-1} \sum _{\text{i1}=1}^{M-\text{r1}} \sum _{\text{j1}=1}^{\text{r1}+\text{i1}} \sum _{\text{k1}=0}^{\text{j1}*(\text{Ne}-1)}
[/tex]
but you have defined :
If[M >= 1, m = M, m = 0];
and M IS 1, so m=M=1;
Then in your sum
[tex]
\sum _{\text{r1}=m}^{M-1} \sum _{\text{i1}=1}^{M-\text{r1}}
[/tex]
you have:
r1 from {m to M-1} which is r1 from {1 to (1-1)} or {1 to 0}
then you have i1 from {1 to M-r1} which is {1 to (1-1)} or {1 to 0}

So it doesn't sum anything.
see :
[tex]
M=1;m=1;\sum _{\text{r1}=m}^{M-1} \sum _{\text{i1}=1}^{M-\text{r1}} 1==0
[/tex]
 
  • #12
Yes, now the fake code is working. I said fake because I gave you fake parameters, so the values you got are not the expected one, because there are not in the range between 0 and 1 as it must be by definition. When I did a slight change toward the real parameters I got the expected results as following:

Code:
A = 23;
Q = 15;
Ne = 21;
Meq[s_] := 1/(1 - 0.5 s)^4 ;
a[n_] = If[n == 0, 2, 1];
For[SNRdB = 0, SNRdB <= 10, SNRdB++,
 SNR = 10^(SNRdB/10);
 Print[Pout = Refine[(1.0) (2^-Q*E^(A/2))/SNR \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(q = 0\), \(Q\)]Binomial[Q, q] \(
\*UnderoverscriptBox[\(\[Sum]\), \(n = 0\), \(Ne + q\)]
FractionBox[
SuperscriptBox[\((\(-1\))\), \(n\)], \(a[n]\)] Re[
\*FractionBox[\(Meq[\(-
\*FractionBox[\(A + \((2*Pi*I*n)\)\), \(2*SNR\)]\)]\), 
FractionBox[\(A + \((2*Pi*I*n)\)\), \(2*SNR\)]]]\)\)]]]

0.142877

0.246246

0.390748

0.564677

0.738295

0.875494

0.956523

0.989842

0.998584

0.999898

0.999997

But when I turn my attention to my real, relatively long code, I faced with the same problem again, although I used the same procedure as you described. I don't know why.

Best Regards
 

1. What is an equation evaluation problem in Mathematica?

An equation evaluation problem in Mathematica refers to the process of using the Mathematica software to solve mathematical equations and expressions. Mathematica is a powerful computational tool that can handle a wide range of mathematical problems, from simple algebraic equations to complex differential equations.

2. How do I input equations into Mathematica?

To input an equation into Mathematica, you can use either traditional mathematical notation or the Wolfram Language syntax. For traditional notation, you can simply type the equation as you would on paper. For the Wolfram Language syntax, you would use the built-in functions and operators to construct the equation. Both methods will provide the same result.

3. What types of equations can be solved using Mathematica?

Mathematica can solve a wide range of equations, including algebraic equations, differential equations, and transcendental equations. It can also handle systems of equations and equations with multiple variables. However, some very complex equations may require additional specialized packages or coding.

4. How does Mathematica solve equations?

Mathematica uses a variety of algorithms and methods to solve equations. These include symbolic methods, numerical methods, and heuristics. Symbolic methods use algebraic manipulation to solve equations, while numerical methods use numerical approximations to find solutions. Heuristics refer to the rules and strategies that Mathematica uses to choose the most efficient method for a particular equation.

5. Can Mathematica solve real-world problems involving equations?

Yes, Mathematica can be used to solve real-world problems involving equations. It is commonly used in fields such as engineering, physics, and finance to solve complex equations and systems of equations. It can also handle large data sets and perform statistical analyses, making it a valuable tool for solving real-world problems.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
245
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Back
Top