# How to translate probability Matlab code into Mathematica?

Posted 8 years ago
6993 Views
|
4 Replies
|
3 Total Likes
|
 I am willing to translate the following Matlab code into Mathematica: M=10^2; h=sqrt(2).*(randn(1,M)+1j.*randn(1,M)); n=sqrt(2).*(randn(1,M)+1j.*randn(1,M)); No=var(n); for z=0:2:20 P=10^(z/10); a=P.*abs(h).^2/No; OutageProb= 1 - (igamma[1,1/ a])^2/M; end z=0:2:20; plot(z,OutageProb) Actually, I would like to know how to implement the above z Loop to get the average outage probability?...However, I translated that code to the following: M = 10^2 h = Sqrt*RandomReal[1, M] + I*RandomReal[1, M]; n = Sqrt*RandomReal[1, M] + I*RandomReal[1, M]; No = Variance[n]; P = 10^(z/10); a = P*(Abs[h])^2/No; OutageProb = 1 - (Gamma[1, 1/a])^2; LogPlot[OutageProb, {z, 0, 20}, PlotRange -> {10^-4, 1}, Frame -> True] Unfortunately, my code has been inaccurate and I would like to know what is the wrong in my code?
4 Replies
Sort By:
Posted 8 years ago
 Thanks David for your answer..The mistake was exist in my last command as I forgot to take the mean of average probability!!!.
Posted 8 years ago
 It would be good to know more about what is being analyzed. But when I execute your code this is what I get. Why do you believe this is incorrect? M = 10^2; h = Sqrt*RandomReal[1, M] + I*RandomReal[1, M]; n = Sqrt*RandomReal[1, M] + I*RandomReal[1, M]; No = Variance[n]; P = 10^(z/10); a = P*(Abs[h])^2/No; OutageProb = 1 - (Gamma[1, 1/a])^2; LogPlot[OutageProb, {z, 0, 20}, PlotRange -> {10^-4, All}, Frame -> True] LogPlot[Mean[OutageProb], {z, 0, 20}, PlotRange -> {10^-4, All}, Frame -> True] Posted 8 years ago
 I think your code is inaccurate as well because when I plot the outage probability theoretically as below, it gave me a figure different from yours. My code should produce a figure close to that one below. In fact, I am still stuck what the wrong in my code? OutageProb = 1 - (Gamma[1, 1/P])^2; LogPlot[OutageProb, {z, 0, 20}, PlotRange -> {10^-4, 1}, Frame -> True] Posted 8 years ago
 I used Table i.o. a For loop and got this: the data gives 11 sets of numbers (one for each value of z) of which this is plot of the first two: M = 10^2; h = Sqrt*RandomReal[1, M] + I*RandomReal[1, M]; n = Sqrt*RandomReal[1, M] + I*RandomReal[1, M]; No = Variance[n]; data = Table[ 1 - (Gamma[1, 1/(10^(z/10)*(Abs[h])^2/No)])^2, {z, 0, 20, 2}]; ListLogPlot[data[[1 ;; 2]], Joined -> True, ImageSize -> 400, AspectRatio -> 1] Does this make any sense?