About uniform distribution pdf.....

I am trying to plot PDF of uniform distribution.... have problem in plotting pdf..
my code is as follows...
a=0;
b=2;
x=rand(1000,1);
y=unifpdf(x,a,b);
Plot(x,y)....
I know the mistake is in plotting ... i mean instade of x in plot what should i do ?
plot should be .5 till for (0,2) and 0 elsewhere........

9 件のコメント

Torsten
Torsten 2015 年 8 月 24 日
1. Write "plot" with a small "p".
2. Your x values are all between 0 and 1. To make a plot of the pdf, you should at least choose the x values to vary in between -1 and 3, say.
Best wishes
Torsten.
rathod ujjval rameshbhai
rathod ujjval rameshbhai 2015 年 8 月 24 日
編集済み: Walter Roberson 2015 年 8 月 24 日
a=0;
b=2;
x = -1 + (3+1)*rand(100,1);
>> y=unifpdf(x,a,b);
>> plot(x,y);
The graf is still wrong why?
rathod ujjval rameshbhai
rathod ujjval rameshbhai 2015 年 8 月 24 日
when I check the 100 values of y some are 0 and some are .5? it should be all .5 as the a=0;b=2;
rathod ujjval rameshbhai
rathod ujjval rameshbhai 2015 年 8 月 24 日
編集済み: rathod ujjval rameshbhai 2015 年 8 月 24 日
If I do a=0;b=3; and take x from 0 to 3 then it is coming ok..... both pdf and cdf. BUT Why not for diffrent values of x and interval (a, b)? Is it nesessary to keep both x and a,b in the same interval?
Walter Roberson
Walter Roberson 2015 年 8 月 24 日
-1 + (3+1)*rand is going to be in the range -1 + 4*0 = -1, up to -1 + 4*1 = 3. The entries that are from -1 to a are going to output 0, and the entries that are from b to 3 are going to output 0.
rathod ujjval rameshbhai
rathod ujjval rameshbhai 2015 年 8 月 24 日
Thanks in short we have to keep range same for both (a,b) and x
Torsten
Torsten 2015 年 8 月 24 日
No.
a=0;
b=2;
x=linspace(a-1,b+1);
y=unifpdf(x,a,b);
plot(x,y)
Best wishes
Torsten.
rathod ujjval rameshbhai
rathod ujjval rameshbhai 2015 年 8 月 24 日
編集済み: rathod ujjval rameshbhai 2015 年 8 月 24 日
Done..... thanks a lot Torsten.... But waht about rand()? Because linespace will generate values in sequence....
Torsten
Torsten 2015 年 8 月 25 日
unifpdf does only plot the analytically given PDF of the uniform distribution within a certain range. It does not work on randomly generated data or something similar.
If you want to plot the empirical CDF, you will have to use "histogram".
Best wishes
Torsten.

サインインしてコメントする。

回答 (0 件)

質問済み:

2015 年 8 月 23 日

コメント済み:

2015 年 8 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by