Matlab estimate PDF from random variable X

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
3 replies · 3K views
Dustinsfl
Messages
2,217
Reaction score
5
How do I estimate the pdf from a random variable \(X\) where \(X = U_1 - U_2\) and \(U_i\) are uniform random variables?

In the code below, I used unifrnd(-5, 5, 1000, 1) which generated a 1000x1 vector of uniform random number between -5 and 5.

How do I estimate the PDF for X?

Code:
rng;
X = unifrnd(-5, 5, 1000, 1) - unifrnd(-5, 5, 1000, 1);
bincenters = (-5:0.5:5);
bins = length(bincenters);

h = zeros(bins, 1);              %  pre-allocating h

for i = 1:length(X)
    for k = 1:bins
        if X(i) > bincenters(k) - 0.5/2 && X(i) <= bincenters(k) + 0.5/2
            h(k, 1) = h(k, 1) + 1;
        end
    end
end

pxest = h/(1000*0.5);

bar(bincenters, pxest)
 
Physics news on Phys.org
dwsmith said:
How do I estimate the pdf from a random variable \(X\) where \(X = U_1 - U_2\) and \(U_i\) are uniform random variables?

In the code below, I used unifrnd(-5, 5, 1000, 1) which generated a 1000x1 vector of uniform random number between -5 and 5.

How do I estimate the PDF for X?

Code:
rng;
X = unifrnd(-5, 5, 1000, 1) - unifrnd(-5, 5, 1000, 1);
bincenters = (-5:0.5:5);
bins = length(bincenters);

h = zeros(bins, 1);              %  pre-allocating h

for i = 1:length(X)
    for k = 1:bins
        if X(i) > bincenters(k) - 0.5/2 && X(i) <= bincenters(k) + 0.5/2
            h(k, 1) = h(k, 1) + 1;
        end
    end
end

pxest = h/(1000*0.5);

bar(bincenters, pxest)

What are you really trying to do?

There is no need to "estimate" this distribution you know it, it is the symmetric triangular distribution with support (-10,10).

Otherwise google "kernel density estimation", or "matlab ksdensity".

.
 
zzephod said:
What are you really trying to do?

There is no need to "estimate" this distribution you know it, it is the symmetric triangular distribution with support (-10,10).

Otherwise google "kernel density estimation", or "matlab ksdensity".

.

I just doing a problem out of a book on stochastic processes.
 
dwsmith said:
I just doing a problem out of a book on stochastic processes.

What is the exact wording of the problem.

.