Hello, I am trying to plot the function below but the result is a weird graph. Here is my code
a=1+randn(1,1e3)*sqrt(1/2);
b=1+randn(1,1e3)*sqrt(1/2);
c=a+b*1i;
g=abs(c);
y=2*(K+1)*exp(-K)/Omega*g.*exp(-((K+1)*g.^2)/Omega).*besseli(0, 2*sqrt(K*(K+1)/Omega).*g); %simulation
plot(g, y);
and here is the graph
How do I make it normal?

 Réponse acceptée

Voss
Voss le 10 Fév 2023
You need to sort g before calculating y (or sort g and y afterwards - not shown here).
% I made up some values for the missing variables. Obviously, you would use
% the correct values here:
K = 1;
Omega = 1;
a=1+randn(1,1e3)*sqrt(1/2);
b=1+randn(1,1e3)*sqrt(1/2);
c=a+b*1i;
g=abs(c);
% sort g so the plotted points are in order
g = sort(g);
y=2*(K+1)*exp(-K)/Omega*g.*exp(-((K+1)*g.^2)/Omega).*besseli(0, 2*sqrt(K*(K+1)/Omega).*g); %simulation
plot(g, y);

2 commentaires

Konstantina Chitou
Konstantina Chitou le 10 Fév 2023
Thank you so much!
Voss
Voss le 10 Fév 2023
You're welcome!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange

Produits

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by