1

If I was using a least squares approximation of the form $y = A_1 + A_2\sin(wx) + A_3\cos(wx)$, would you be minimising the function $\sum_{i=0}^n (y_i - (A_1 + A_2\sin(wx) + A_3\cos(wx))^2$ ?

I've never tried this for periodic data before!

mdp
  • 14,671
  • 1
  • 39
  • 63
Sanya
  • 61

2 Answers2

0

The least squares method takes a trial function, $y(x)$, and a set of $m$ data points $\left\{ x_{k}, y_{k} \right\}_{k=1}^{m}$ and provides the best solution vector $A=\left(A_1, A_2, A_3\right).$

Define the residual error as the difference between the data and the prediction as $r_k (A) = y_k - y(x_k).$ The method is named for minimizing the sum of the squares of the residual errors. That is, the solution vector is defined as $$ r^{2}(A) = \left\{ A \in \mathbb{R}^{3} \colon \sum_{k=1}^{m} \left(y_k - y(x_k) \right)^{2} \text{ is minimized} \right\} $$

The system your problem is $$ \left[ \begin{array}{ccc} 1 & \sin (w x_1 ) & \cos (w x_1 ) \\ 1 & \sin (w x_2 ) & \cos (w x_2 ) \\ \vdots & \vdots & \vdots \\ 1 & \sin (w x_m ) & \cos (w x_m ) \end{array} \right] \left[ \begin{array}{c} A_1 \\ A_2 \\ A_3 \end{array} \right] = \left[ \begin{array}{} y_1 \\ y_2 \\ \vdots \\ y_m \end{array} \right], $$ which is manifestly linear in the fit parameters. Solve via the normal equations if the data is well conditioned, or QR, SVD decompositions, etc.

So yes, you would be minimizing $$ \begin{align} r^{2}(A_1,A_2,A_3) &= \Bigg\lVert \left[ \begin{array}{ccc} 1 & \sin (w x_1 ) & \cos (w x_1 ) \\ 1 & \sin (w x_2 ) & \cos (w x_2 ) \\ \vdots & \vdots & \vdots \\ 1 & \sin (w x_m ) & \cos (w x_m ) \end{array} \right] \left[ \begin{array}{c} A_1 \\ A_2 \\ A_3 \end{array} \right] - \left[ \begin{array}{} y_1 \\ y_2 \\ \vdots \\ y_m \end{array} \right] \Bigg\rVert_{2}^{2} \\ &= \sum_{k=1}^{m} \left( y_k - A_1 - A_2 \sin \left( w x_k \right) - A_3 \cos \left( w_k \right) \right)^2. \end{align} $$

Keep in mind that the best fit may not be a good fit. If you have a bad trial function, you will get the best fit for a bad model.

dantopa
  • 10,342
0

A straightforward method (no initial gess neeeded, no iterative computation) is shown pages 34-36 in : http://fr.scribd.com/doc/14674814/Regressions-et-equations-integrales

JJacquelin
  • 66,221
  • 3
  • 37
  • 87