Message Boards Message Boards

0
|
7635 Views
|
4 Replies
|
3 Total Likes
View groups...
Share
Share this post:

How to translate probability Matlab code into Mathematica?

Posted 9 years ago

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[2]*RandomReal[1, M] + I*RandomReal[1, M];
n = Sqrt[2]*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?

POSTED BY: John G
4 Replies
Posted 9 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 BY: John G
Posted 9 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[2]*RandomReal[1, M] + I*RandomReal[1, M];

n = Sqrt[2]*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]

enter image description here

LogPlot[Mean[OutageProb], {z, 0, 20}, PlotRange -> {10^-4, All}, 
 Frame -> True]

enter image description here

POSTED BY: David Keith
Posted 9 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] 

outage prob versus z

POSTED BY: John G
Posted 9 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[2]*RandomReal[1, M] + I*RandomReal[1, M];
n = Sqrt[2]*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]

enter image description here

Does this make any sense?

POSTED BY: Erik Mahieu
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract