title: Need Help in Writting Matlab Code for Sum of Independent Random Variables
body: <p>I want to write a MATLAB code for the <a href="http://en.wikipedia.org/wiki/Probability_density_function#Sums_of_independent_random_variables" rel="nofollow">convolution of density functions</a> . </p>
  
  <p>For random variables X (with PDF f_x)and Y(with PDF f_y), the PDF of their summation, X+Y, can be obtained by the following MATLAB code:</p>
  
  <pre><code>function p=sumX_Y(z,mean1,sigma1,mean2,sigma2)
  G = @(y)f_x(mean1,sigma1,z-y).*f_y(mean2,sigma2,y);p= integral(G,-Inf,Inf);
  </code></pre>
  
  <p>Now for summation of three random variable X+Y+Z it should be </p>
  
  <pre><code>function p=sumX_Y_Z(z,mean1,sigma1,mean2,sigma2,mean3,sigma3)
      G = @(y)sumX_Y(z-y,mean1,sigma1,mean2,sigma2).*f_z(mean3,sigma3,y);p= integral(G,-Inf,Inf);
  </code></pre>
  
  <p>But it will not work since the first input of the function sumX_Y is not of type double. I would appreciate if you could help me to fix this problem. </p>
  
  <p>I also want to find the PDF for sum of more than 3 random variable and I do not know how to write the algorithm. Thanks a lot!</p>