title: How do I properly setup numerical integration in MATLAB?
body: <p>I'm looking to integrate this expression:</p>
  <p><img src="https://i.stack.imgur.com/Txw2l.png" alt="Normal Distribution function:" /></p>
  <p>However I seem to be having problems setting up the function.  As outlined in <a href="http://www.mathworks.com/help/techdoc/ref/quad.html" rel="nofollow noreferrer">this</a> MATLAB explanation, I've defined a separate function named 'NDfx.m' which looks like this:</p>
  <pre><code>    function [ y ] = NDfx(x)
      
      y = (1/sqrt(2*pi))*exp(-.5*x^2); % Error occurs here
      
      end
  </code></pre>
  <p>However when I call it within my main function I get an error at the commented line above.  My main function looks like this:</p>
  <pre><code>function[P] = NormalDistro(u,o2,x)
  
  delta = x-u;
  dev = abs((delta)/o2);           % Normalizes the parameters entered into function
  P_inner = quad(@NDfx,-dev,dev);  % Integrates function NDfx from -dev to dev (error here)
  P_outer = 1 - P_inner;           % Calculation of outer bounds of the integral
  
  if delta &gt; 0
      P = P_inner + (P_outer/2);
      
  elseif delta &lt; 0
      P = P_outer/2;
  
  elseif dev == 0
      P = .5;
      
  end
  end
  </code></pre>
  <p>The specific error that I get is:</p>
  <blockquote>
  <p>Error in ==&gt; mpower</p>
  <p>Inputs must be a scalar and a square matrix</p>
  </blockquote>