Filter löschen
Filter löschen

how to generate a traingular distrbution (sawtooth model) ?

2 Ansichten (letzte 30 Tage)
Amr Hashem
Amr Hashem am 27 Okt. 2015
Kommentiert: Star Strider am 27 Okt. 2015
I want to generate a random (n=100)sawtooth model with width (b=24)
1st (t=0)start at 0, 2nd at 1 .... nth at n=100
t is random variable with gaussian pdf (mu=1 and st.dev=3)
finally I want to add them like:
to form a shape of summation of 100 random sawtooth model
I try:
n=100;
a=0;b=130;c=61;
u=rand(n,1);
x=zeros(n,1);
for i=1:n
U=u(i);
if U<(c-a)/(b-a)
X=a+sqrt(U*(b-a)*(c-a));
else
X=b-sqrt((1-U)*(b-a)*(b-c));
end
x(i)=X;
end
figure
hist(x,100)
which produce this figure
its a good summation model , but not perfectly what I want .
how to generate this distribution?

Akzeptierte Antwort

Star Strider
Star Strider am 27 Okt. 2015
Bearbeitet: Star Strider am 27 Okt. 2015
Guessing here, but if you want a Gaussian pdf with a mean of 1 and a standard deviation of 3, consider replacing the ‘u’ assignment with:
u = 1 + 3*randn(n,1);
The rand function produces uniformly-distributed random numbers on the interval [0,1].
  6 Kommentare
Amr Hashem
Amr Hashem am 27 Okt. 2015
Bearbeitet: Amr Hashem am 27 Okt. 2015
Thanks...
I adjust your last line.
plot(t, sawshift(:,1:121))
Star Strider
Star Strider am 27 Okt. 2015
My pleasure.
Noted. I used my original code in the revised figure(1) plot. (It worked there.)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by