Matlab estimate PDF from random variable X

Click For Summary

Discussion Overview

The discussion revolves around estimating the probability density function (PDF) of a random variable \(X\) defined as the difference between two uniform random variables \(U_1\) and \(U_2\). Participants explore methods for estimating this PDF using MATLAB, while also addressing the theoretical understanding of the distribution involved.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Homework-related

Main Points Raised

  • One participant presents MATLAB code to estimate the PDF of \(X = U_1 - U_2\) using a histogram approach.
  • Another participant suggests that the distribution of \(X\) is known to be a symmetric triangular distribution with support (-10, 10), implying that estimation may be unnecessary.
  • A later reply questions the purpose of the estimation, indicating that the problem is derived from a book on stochastic processes.
  • There is a suggestion to explore kernel density estimation methods in MATLAB, such as using the `ksdensity` function.

Areas of Agreement / Disagreement

Participants express differing views on the necessity of estimating the PDF, with some asserting that the distribution is already known while others are focused on the estimation process itself. The discussion remains unresolved regarding the need for estimation versus theoretical understanding.

Contextual Notes

Participants have not provided the exact wording of the problem from the book, which may limit understanding of the context in which the estimation is being performed.

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.

.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 44 ·
2
Replies
44
Views
6K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
3
Views
3K
Replies
2
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K