title: How to find intersection of two distribution in Matlab
body: <p>As the title, I am trying to find the intersection of two probability density function to locate the optimal decision point with minimum decision error.</p>
  
  <p>In my case, 
  One distribution is Rayleigh distribution and the other one is Rician 
  distribution.</p>
  
  <p>(you can think Rayleigh and Rician both as Gaussian distribution, because the problem I am trying to state would also occur in Gaussian case.)</p>
  
  <p>To generate two vectors corresponding to each pdf.</p>
  
  <pre><code>Fs=1000;
  x=linspace(0,20,Fs*20)
  Ray=pdf('Rayleigh',x,1);
  Ric=pdf('rician',x,3,1);
  </code></pre>
  
  <p>Intuitively, to find the intersection point of these two pdf.</p>
  
  <p>I set a certain threshold, say</p>
  
  <pre><code>epsilon=0.001;
  </code></pre>
  
  <p>and traverse through all the vector elements of both vectors.</p>
  
  <p>if the difference of elements bewteen two vectors are smaller than that threshold, then record the index.</p>
  
  <p>if the intersection happens near </p>
  
  <pre><code>index=350, 
  </code></pre>
  
  <p>then i can expect that the difference of value of these index</p>
  
  <pre><code>347, 348, 349, 350, 351, 352, 353, 
  </code></pre>
  
  <p>will be smaller than epsilon
  ,then I choose the median , that is, index=350 ,to represent the intersection point of two distribution. </p>
  
  <p>Now the problem is that because of the nature of these pdf, the value are both very close to zero in the very beginning and the tail.</p>
  
  <p>So, no matter how I choose epsilon , the index that are recorded would be something like</p>
  
  <pre><code>1,2,347, 348, 349, 350, 351, 352, 353, 6000,6001,6002,6003,6004,6005,6006.....
  </code></pre>
  
  <p>How can I solve this problem? , or is there any robust way to find the intersection of two pdfs in Matlab? (I think this functionality should be quite fundamental.)</p>