title: Use Matlab to get maximum value of the density function of inverse Gaussian distribution
body: <p>New to Matlab and here is my question.</p>
  
  <p>Question: Need to use the rejection method to <strong>find the maximum value</strong> of the density function of inverse Gaussian distribution as shown below. </p>
  
  <p><a href="https://i.stack.imgur.com/Ek8Xm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ek8Xm.png" alt="enter image description here"></a></p>
  
  <pre><code>% Using Rejection Method to generate standard normal N(0,1). 
  % Check how many realizations have been rejected 
  
  rng(123);
  N = 100000;
  Count = 0;
  Rejection = 0;
  X = [];
  tic %Timer
  while Count&lt;= N
     U1 = -4+(4-(-4))*rand; % U1: Uniform(-4, 4)
     U2 = 0.5*rand; % U2: Uniform(0, 0.5)
     if U2&lt;= 1/(sqrt(2*pi))*exp(-U1^2/2)
         Count = Count + 1;
         X = [X,U1];
     else
        Rejection = Rejection + 1; 
     end
  </code></pre>
  
  <p>Please feel free to let me know if u need any other information. Thank you!</p>