title: Non-linear Fit with Independent Variable as Integral Bound
body: <p>I am trying to use <em>Matlab</em> to fit a dataset (with vectors <em>x</em> and <em>y</em>) to a function <em>x(y)</em>, in which <em>y</em> appears as the upper bound of an integral and the fitting parameter is the lower bound.</p>
  
  <p>I have defined two functions:</p>
  
  <pre><code>p = @(x,a) sqrt((1 - x.^2 / a.^2).^(-2) - 1)
  x = @(y, a, y0, x0) quad(@(x) 1 ./ p(x,a), y0, y) + x0
  </code></pre>
  
  <p>My data points are stored in a dataset called <code>data</code>.</p>
  
  <p>I am now trying to call:</p>
  
  <pre><code>nlinfit(data.y, data.x, @(c, y) x(y, 0.0027, c(1), 0.001), 0.00001)
  </code></pre>
  
  <p>However, the following error is generated:</p>
  
  <pre><code>Error using nlinfit (line 142)
  Error evaluating model function '@(c,y)x(y,0.0027,c(1),0.001)'.
  Caused by:
      Error using quad (line 66)
      The limits of integration must be scalars.
  </code></pre>
  
  <p>How can I convince <em>Matlab</em> to do a non-linear fit for <code>y0</code>?</p>
  
  <p>I am new to working with <em>Matlab</em>. However, I have already solved this problem in <em>Mathematica</em> with just three lines, so I suppose I am making a rather simple error...</p>