title: R - Singular gradient matrix at initial parameter estimates
body: <p>I'm trying to fit a harmonic equation to my data, but when I'm applying the <code>nls</code> function, R gives me the following error:</p>
  <blockquote>
  <p>Error in nlsModel(formula, mf, start, wts) : singular gradient matrix at initial parameter estimates.</p>
  </blockquote>
  <p>All posts I've seen, related to this error, are of exponential functions, where a linearization is used to fix this error, but in this case, I'm not able to solve it in this way. I tried to use other starting points but it still not working.</p>
  <p><strong>CODE:</strong></p>
  <pre><code>y &lt;- c(20.91676, 20.65219, 20.39272, 20.58692, 21.64712, 23.30965, 23.35657, 24.22724, 24.83439, 24.34865, 23.13173, 21.96117)
  t &lt;- c(1, 2, 3, 4 , 5 , 6, 7, 8, 9, 10, 11, 12)
  
  
  # Fitting function
  
  fit &lt;- function(x, a, b, c) {a+b*sin(2*pi*x)+c*cos(2*pi*x)}
  
  res &lt;- nls(y ~ fit(t, a, b, c), data=data.frame(t,y), start = list(a=1,b=0, c=1))
  </code></pre>
  <p>Can you help me? Thanks!</p>