Modified bessel function in Mathematica

Hello,

Is there any body can help me to execute the below equation using For loop of the product in Mathematica…Thanks for your cooperation

Equation#.jpg

You don’t actually need a for loop. Mathematica has a product function built in that can accept iterators. For example, if lambda is a 4 by M matrix of parameter values, you can type in this formula pretty much exactly as it appears.

Type escape prodt escape to get that product notation, or you can just use the Product function, like so:

Product[1 - 
  4 (2^(2 r) - 1)/(s n r) Sqrt[Product[\[Lambda][[k, m]], {k, 1, 4}]]
    k1 (Sqrt[
    4 \[Lambda][[1, m]] \[Lambda][[2, m]] (2^(2 r) - 1)/(
     s n r)]) k1 (Sqrt[
    4 \[Lambda][[3, m]] \[Lambda][[4, m]] (2^(2 r) - 1)/(s n r)]), {m,
   1, M}]

Hi Richard,

Thanks so much for your response and interest..In fact, I am a new user in Mathematica and found Mathematica is better that Matlab for saving time!!. However, I have tried to execute your code but the result produced with errors as mentioned below. Is it possible to get your suggestions?.

Part::pspec: Part specification m is neither a machine-sized integer nor a list of machine-sized integers. >>
General::stop: Further output of Part::pspec will be suppressed during this calculation. >>
Part::partd: Part specification \[[1,1]] is longer than depth of object. >>
Part::partd: Part specification \[[2,1]] is longer than depth of object. >>
Part::partd: Part specification \[[3,1]] is longer than depth of object. >>
General::stop: Further output of Part::partd will be suppressed during this calculation. >>

Regards,
Yahia

You’ll need to define lambda first, otherwise it’s trying to take elements from a matrix that doesn’t exist. You’ll also need to have your other parameters defined if you want a numeric output instead of a symbolic expression. As an example, if I had the following (randomly generated) values for lambda

\[Lambda] = RandomReal[1, {4, 5}] (*using M=5 here*)
{{0.677488,0.632777,0.248209,0.0187061,0.193736},
{0.115021,0.632859,0.931393,0.730297,0.298366},
{0.204479,0.266129,0.831798,0.689316,0.55112},
{0.301503,0.965564,0.208395,0.0999985,0.495401}}

The product gives

If there were also values defined for s, n, r, and k1, it would evaluate to a single real number.

To visualize how it works, I can set up symbolic values for lambda like so:

\[Lambda] = Table[
  Symbol[ToString[\[Lambda]] <> ToString[k] <> ToString[m]],
  {k, 1, 4}, {m, 1, 5}] (*again using M=5, but it could be any natural number*)

This creates a symbolic matrix with the following structure:

{{\[Lambda]11, \[Lambda]12, \[Lambda]13, \[Lambda]14, \[Lambda]15},
{\[Lambda]21, \[Lambda]22, \[Lambda]23, \[Lambda]24, \[Lambda]25},
{\[Lambda]31, \[Lambda]32, \[Lambda]33, \[Lambda]34, \[Lambda]35},
{\[Lambda]41, \[Lambda]42, \[Lambda]43, \[Lambda]44, \[Lambda]45}}

Also, since M is dependent on the number of columns of lambda, it makes sense to just define it as

M = Length[Transpose[\[Lambda]]]

Then evaluation of the product

Product[
 1 - 4 (2^(2 r) - 1)/(s n r) Sqrt[
    Product[\[Lambda][[k, m]], {k, 1, 4}]
    ] k1 (Sqrt[
     4 \[Lambda][[1, m]] \[Lambda][[2, m]] (2^(2 r) - 1)/(s n r)
     ]) k1 (Sqrt[
     4 \[Lambda][[3, m]] \[Lambda][[4, m]] (2^(2 r) - 1)/(s n r)
     ]), {m, 1, M}]

then gives the following output:

(1 - (16 (-1 + 2^(
      2 r)) k1^2 Sqrt[((-1 + 2^(2 r)) \[Lambda]11 \[Lambda]21)/(
    n r s)] Sqrt[((-1 + 2^(2 r)) \[Lambda]31 \[Lambda]41)/(n r s)]
     Sqrt[\[Lambda]11 \[Lambda]21 \[Lambda]31 \[Lambda]41])/(
   n r s)) (1 - (
   16 (-1 + 2^(
      2 r)) k1^2 Sqrt[((-1 + 2^(2 r)) \[Lambda]12 \[Lambda]22)/(
    n r s)] Sqrt[((-1 + 2^(2 r)) \[Lambda]32 \[Lambda]42)/(n r s)]
     Sqrt[\[Lambda]12 \[Lambda]22 \[Lambda]32 \[Lambda]42])/(
   n r s)) (1 - (
   16 (-1 + 2^(
      2 r)) k1^2 Sqrt[((-1 + 2^(2 r)) \[Lambda]13 \[Lambda]23)/(
    n r s)] Sqrt[((-1 + 2^(2 r)) \[Lambda]33 \[Lambda]43)/(n r s)]
     Sqrt[\[Lambda]13 \[Lambda]23 \[Lambda]33 \[Lambda]43])/(
   n r s)) (1 - (
   16 (-1 + 2^(
      2 r)) k1^2 Sqrt[((-1 + 2^(2 r)) \[Lambda]14 \[Lambda]24)/(
    n r s)] Sqrt[((-1 + 2^(2 r)) \[Lambda]34 \[Lambda]44)/(n r s)]
     Sqrt[\[Lambda]14 \[Lambda]24 \[Lambda]34 \[Lambda]44])/(
   n r s)) (1 - (
   16 (-1 + 2^(
      2 r)) k1^2 Sqrt[((-1 + 2^(2 r)) \[Lambda]15 \[Lambda]25)/(
    n r s)] Sqrt[((-1 + 2^(2 r)) \[Lambda]35 \[Lambda]45)/(n r s)]
     Sqrt[\[Lambda]15 \[Lambda]25 \[Lambda]35 \[Lambda]45])/(n r s))

(which looks nicer in Mathematica than it does on here).

I may be wrong, but it seems to me that K1 is the Bessel function, not a multiplier, and square roots in round parenthesis are arguments of K1.

I somehow totally missed that part in the title of the post. In that case, this would be more helpful (but no guarantees, I haven’t slept in a while):

Product[
1-4 (2^(2r)-1)/(s n r) 
Sqrt[Product[?[[k,m]],{k,1,4}]] 
BesselK[1,Sqrt[4?[[1,m]]?[[2,m]] (2^(2r)-1)/(s n r)]] 
BesselK[1,Sqrt[4?[[3,m]]?[[4,m]] (2^(2r)-1)/(s n r)]],
{m,1,M}]

Thanks for the code, Richard! I think if we replace in that code

/. Part -> Subscript

We can avoid necessity of defining lambda:

Product[1 - (4*(-1 + 2^(2*r))*BesselK[1, 2*Sqrt[((-1 + 2^(2*r))*Subscript[\[Lambda], 1, m]*Subscript[\[Lambda], 2, m])/(n*r*s)]]*
 BesselK[1, 2*Sqrt[((-1 + 2^(2*r))*Subscript[\[Lambda], 3, m]*Subscript[\[Lambda], 4, m])/(n*r*s)]]*
 Sqrt[Subscript[\[Lambda], 1, m]*Subscript[\[Lambda], 2, m]*Subscript[\[Lambda], 3, m]*Subscript[\[Lambda], 4, m]])/(n*r*s), {m, 1, M}]

I like it! That definitely looks much nicer and is far more intuitive.

Both solutions are correct and I have already obtained positive results of the outage probability..By the way, SNR means signal to noise ratio..Thanks for your support.

Modified bessel function in Mathematica

m = (0.6102*n) + 0.4263;
\[CapitalOmega] = (0.8808*n^-0.9661) + 1.12;
n = 2;
X = 2^(2 R) - 1;
R = 1;
M = 4;

\[Lambda] = RandomReal[1, {2, 4}];

f=Product[1-(Gamma[m,(m (((-1+4^R) Subscript[\[Lambda],1,i])/S)^(1/n))/\[CapitalOmega]] Gamma[m,(m ((X Subscript[\[Lambda],2,i])/S)^(1/n))/\[CapitalOmega]])/Gamma[m]^2,{i,1,4}]/.Subscript->Part;

Plot[f, {S, 0, 1}]

If you replace Subscript with Part it seems to work.