title: Nonlinear least squares curve fitting in R
body: <p>I am new to R (first time using it). and I am following this tutorial <a href="http://www.walkingrandomly.com/?p=5254" rel="nofollow noreferrer">http://www.walkingrandomly.com/?p=5254</a> to try to plot a curve and discover the function that best fits my data. So far I have tryed:</p>
  
  <pre><code>&gt; xdata = c(1 ,5, 10, 20, 100)
  &gt; ydata = c(23.83333333, 210.3666667, 545.3666667, 1756.866667, 38595.7)
  &gt; plot(xdata,ydata)
  </code></pre>
  
  <p>So I get this:</p>
  
  <p><img src="https://i.stack.imgur.com/GhktH.png" alt="enter image description here"></p>
  
  <p>Then I try:</p>
  
  <pre><code>&gt; p1 = 1
  &gt; p2 = 0.2
  &gt; fit = nls(ydata ~ xdata^2, start=list(p1=p1,p2=p2))
  </code></pre>
  
  <p>And I get this error:</p>
  
  <pre><code>Error in nlsModel(formula, mf, start, wts) : 
    singular gradient matrix at initial parameter estimates
  </code></pre>
  
  <p>What am I doing wrong?
  Thanks</p>