Different Values, Constanst Results in Mathematica

  • Mathematica
  • Thread starter EngWiPy
  • Start date
  • Tags
    Mathematica
In summary, the code calculates the fractional value of a number raised to a power, given a starting value and an exponent.
  • #1
EngWiPy
1,368
61
Hello,

I have the following piece of code in Mathematica:

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

Despite the variable "SNR" changed in each iteration of the for loop, the printed result is the same in all iterations. Why is this?

Thanks in advance
 
Physics news on Phys.org
  • #2
That is correct. The formula you posted does in fact give the same value for different values of SNRdB.
 
  • #3
DaleSpam said:
That is correct. The formula you posted does in fact give the same value for different values of SNRdB.

Thank you DaleSpam, your answer made me double check and think about the problem, and the problem was a logical one. Some parameters must be fixed and others must be changed, while what I did was that I changed all variables altogether.

Best regards
 
  • #4
Ahh, ok. One thing you might think of doing is setting up a function that takes all of the parameters. That makes evaluating it at different values much easier.
 
  • #5
DaleSpam said:
Ahh, ok. One thing you might think of doing is setting up a function that takes all of the parameters. That makes evaluating it at different values much easier.

Execuse me, I didn't get you. Can you elaborate please.
 
  • #6
For example:

Code:
f[n_, Q_, q_, A_, gC_, Na_, SNR_] := 
(-1)^n/a[n] ((2^-Q*E^(A/2))/SNR*\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(q = 0\), \(Q\)]\(Binomial[Q, q]*\(
\*UnderoverscriptBox[\(\[Sum]\), \(n = 0\), \(Na + q\)]
FractionBox[
SuperscriptBox[\((\(-1\))\), \(n\)], \(a[n]\)] Re[
\*FractionBox[\(MGF[\(-
\*FractionBox[\(A + \((2*Pi*I*n)\)\), \(2*SNR\)]\), gC]\), 
FractionBox[\(A + \((2*Pi*I*n)\)\), \(2*SNR\)]]]\)\)\)) + (E^-A/( 
      1 - E^-A) + (E^(A/2)*2^-Q)/SNR \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(q = 0\), \(Q\)]\(
\*SuperscriptBox[\((\(-1\))\), \(Na + q + 1\)]*Binomial[Q, q]*Re[
\*FractionBox[\(MGF[\(-
\*FractionBox[\(A + \((2*Pi*I \((Na + q + 1)\))\)\), \(2*SNR\)]\), 
          gC]\), 
FractionBox[\(A + 2*Pi*I \((Na + q + 1)\)\), \(2*SNR\)]]]\)\))

Then your for loop is cleaner and easier to debug since you just call f in each iteration with different values for the arguments.
 
  • #7
DaleSpam said:
For example:

Code:
f[n_, Q_, q_, A_, gC_, Na_, SNR_] := 
(-1)^n/a[n] ((2^-Q*E^(A/2))/SNR*\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(q = 0\), \(Q\)]\(Binomial[Q, q]*\(
\*UnderoverscriptBox[\(\[Sum]\), \(n = 0\), \(Na + q\)]
FractionBox[
SuperscriptBox[\((\(-1\))\), \(n\)], \(a[n]\)] Re[
\*FractionBox[\(MGF[\(-
\*FractionBox[\(A + \((2*Pi*I*n)\)\), \(2*SNR\)]\), gC]\), 
FractionBox[\(A + \((2*Pi*I*n)\)\), \(2*SNR\)]]]\)\)\)) + (E^-A/( 
      1 - E^-A) + (E^(A/2)*2^-Q)/SNR \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(q = 0\), \(Q\)]\(
\*SuperscriptBox[\((\(-1\))\), \(Na + q + 1\)]*Binomial[Q, q]*Re[
\*FractionBox[\(MGF[\(-
\*FractionBox[\(A + \((2*Pi*I \((Na + q + 1)\))\)\), \(2*SNR\)]\), 
          gC]\), 
FractionBox[\(A + 2*Pi*I \((Na + q + 1)\)\), \(2*SNR\)]]]\)\))

Then your for loop is cleaner and easier to debug since you just call f in each iteration with different values for the arguments.

Yes, you are right. I will try do this. Thanks
 

Related to Different Values, Constanst Results in Mathematica

1. What is the significance of "Different Values, Constant Results" in Mathematica?

"Different Values, Constant Results" refers to the concept of inputting different values into a mathematical function in Mathematica, but obtaining the same result each time. This is possible due to the symbolic nature of Mathematica, where it can perform calculations and manipulate expressions without assigning specific numerical values to variables.

2. How does Mathematica ensure constant results with different values?

Mathematica uses a technique called symbolic computation, where it represents mathematical expressions as symbols rather than specific numerical values. This allows it to perform operations and simplifications on these symbols, resulting in consistent results regardless of the input values.

3. Are there any limitations to achieving constant results in Mathematica?

While Mathematica can handle a wide range of mathematical functions and operations, there may be some cases where it cannot produce constant results with different values. This can occur if the function involves complex mathematical concepts or if the input values are too large or small to be accurately represented by Mathematica.

4. Can "Different Values, Constant Results" be beneficial in scientific research?

Yes, the ability of Mathematica to produce consistent results with different values can be extremely useful in scientific research. It allows for quick and efficient testing of various input values without the need for manual calculations, making it a valuable tool for data analysis and modeling.

5. How can I use Mathematica to explore "Different Values, Constant Results" in my research?

You can use Mathematica's built-in functions and tools to input different values and observe the resulting output. You can also use the Manipulate function to create interactive visualizations and explore how changing input values affects the output. Additionally, there are many online resources and tutorials available to help you learn and utilize Mathematica's capabilities for your research.

Similar threads

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