title: Computing and plotting pdf of U as a function of two uniformly distributed random variables
body: <p>I am working on a joint pdf problem in which the random variable</p>
  
  <pre><code>U = sqrt(X^2+Y^2)
  </code></pre>
  
  <p><code>X</code> and <code>Y</code> are uniformly distributed over <code>(-2,2)</code>. I want to plot joint pdf of <code>X</code> and <code>Y</code>. Then compute pdf of <code>U</code> and plot it as well. I am using matlab R2011a, and so far, I have come up with the following code. On running the code I got an error message</p>
  
  <pre><code>Undefined function or method 'makedist' for input arguement type 'char'.
  </code></pre>
  
  <p>I found out that makedist is not on 2011 version. So I tried using</p>
  
  <pre><code>a=-2;
  b=2;
  X=a+(b-a)*rand(-10,10);
  Y= a+(b-a)*rand(-10,10).
  </code></pre>
  
  <p>However, I am not sure how to compute pdfs of <code>X</code> and <code>Y</code>, and then joint pdf of <code>XY</code> from this. Any help, partial or holistic, is appreciated. </p>
  
  <p>Here is the matlab code for the problem</p>
  
  <pre><code>%% Create distribution objects for X~U(-2,2) and Y~U(-2,2)
  
  pdx=makedist('Uniform','lower',-2,'upper',2);
  
  pdy=makedist('Uniform','lower',-2,'upper',2);
  
  %Compute the pfs
  
  x_ref=-10:1:10;
  
  y_ref=-10:1:10;
  
  pdf_x=pdf(pdx,x_ref);
  
  pdf_y=pdf(pdy,y_ref);
  
  % Plot the pdfs
  
  figure 1;
  
  stairs(x_ref,pdf_x,'g','Linewidth',2);
  
  hold on;
  
  stairs(y_ref,pdf_y,'r','Linewidth',2);
  ylim([0 1.5]);
  
  hold off;
  
  % Joint pdf of x and Y
  
  pdfXY=pdf_x*pdf_y;
  figure 2;
  
  plot(pdfXY);
  
  %CDF and PDF of U 
  
  U=sqrt(X^2+Y^2);
  
  Umin=0;
  
  Umax=sqrt(b^2+b^2);
  
  a=lower;
  
  b=upper;
  
  x=sqrt(U^2-Y^2);
  
  xmin=0;
  
  xmax=x;
  
  ymin=0;
  
  ymax=U;
  
  Ucdf=integral2(pdfXY,xmin,xmax,ymin,ymax);
  
  % plot CDF of U
  
  figure 3;
  
  plot(Ucdf)
  </code></pre>
  
  <hr>
  
  <p><em>I am just looking to plot the regions than for any specific sample set. <code>X</code> and <code>Y</code> are continuous independent uniform random variables.</em></p>