Hello !
I have a 1x301 array (vector V) of equally sparsed values generated with linspace(0,1,301) and I would like to create a gaussian from those values.
The gaussian should be centered on the middle of the vector V and the central value generated by the gaussian should be 1 (the sigma, spread, is not important).
I tried several ways to do it but I can't manage to obtain a bell curve distribution of Y values over my X axis.
So far I had:
V = linspace(0,L,301)
sigma = 1;
nu = V(length((V-1)/2));
x = V-nu;
T0 = (1/(sigma*sqrt(2)))*exp(-((1/2)*((x/sigma).^2)));
What should I write instead ? It feels like it comes from my gaussian expression.
Thank you in advance !

 Réponse acceptée

Vladimir Sovkov
Vladimir Sovkov le 11 Jan 2020
L=20;
V = linspace(0,L,301);
sigma = L/20;
T0 = exp(-((V-mean(V))/sigma).^2/2);
plot(V,T0);

4 commentaires

KALYAN ACHARJYA
KALYAN ACHARJYA le 11 Jan 2020
Modifié(e) : KALYAN ACHARJYA le 11 Jan 2020
Right :) +1
V.D-C
V.D-C le 11 Jan 2020
Thank you so much !! It works like a charm ! Can you explain to me how you came up with the L being divided by specifically 20 to compute the sigma ?
I tried with L = 1 and sigma = 1/20 and it works too, but not when I do sigma = 1.
Vladimir Sovkov
Vladimir Sovkov le 11 Jan 2020
The step in L (=L/300 in your case) should be smaller than sigma (at least, about 5 or more times smaller). If the step was too big, the significant part of the plot could occur somewhere between the knots, and you would just miss it in the graph. If L was smaller than ~6*sigma, you would only see a narrow central part of the Gaussian, which is not definitely satisfying. If L was too big compared to sigma, the Gaussian would be located in a very narrow central range, and you would have to zoom in in order to see it.
V.D-C
V.D-C le 11 Jan 2020
Thank you very much for your explanations :)

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by