How to minimize a function without using a loop
<p>I have a function (ExpSemivariance) that creates a vector of 11 elements. This elements are then represented on a graph in a scattered diagram and I intend finding the curve (Theoretical) that best fit 'ExpSemivariance' by using mimimum residual (in this case, but any other minimization function can be used)</p>

<pre><code>Nug = 5;
Sill = 7899;
alpha = 1.7;

Step = 10;
q = 11;

      for i=1:q
          Theoretical(i,1) = Nug+Sill*(1-exp(-(Lag(i,1)/R)^alpha));
      end
      Error = sum(abs(Theoretical-ExpSemivariance));
      while Step &gt; 1
          R = R + Step;
          for i=1:q
              Theoretical(i,1) = Nug+Sill*(1-exp(-(Lag(i,1)/R)^alpha));
          end
          error = sum(abs(Theoretical-ExpSemivariance));
          if error &gt; Error
              R = R - Step;
              Step = Step/2;
          else
              Error = error;
          end
      end
</code></pre>

<p>With the only variable being 'R', the script above Works quite well. </p>

<p>The problem is, i am assuming alpha is 1.7. But I actually need to find the correct value of alpha (ranging from 1:2, steps 0.1) and R (ranging from 1-4000) simultaneously which best minimizes the minimizes the error (between ExpSemivariance and Theoretical). Is there an appropriate way to do this?</p>

<p>Thanks</p>