Solving a linear least squares problem with trigonometric functions We want to calculate the amplitude $A$ and the phase angle $\phi$ of the oscillation $b(t)=A\sin(2t+\phi)$.
We have $t_k=(0,\pi/4, \pi/2, 3\pi/4)$ and $b_k=(1.6,1.1,-1.8,0.9)$
Use $\sin(A+B)=\sin(A)\cos(B)+\cos(A)\sin(B)$ and $\alpha=A\cos(\phi), \beta=A\sin(\phi)$ to get a linear problem.
We get $b(t)=\alpha\sin(2t)+\beta\cos(2t)$
Using the above, we get $b^T=A (\alpha, \beta)^T$
Using QR and/or normal equation [ code:https://hastebin.com/otezejobaj.pl ] we get $\alpha=0.1, \beta=1.7$
Now, I should write down the residual vectors for QR and for the normal equation
Question 1: Are the residual vectors here: $Ax_1 - b$ and $Ax_2-b$ with $x_1=(\alpha,\beta)$ from QR Method and $x_2=(\alpha,\beta)$ from the normal equation. (It's the same result here)?
Now, I should calculate $A$ and $\phi$. How should I do that numerically? Also, I noted the following:
(1)$\beta = A\sin(\phi) \Rightarrow 1.7=a\sin(\phi)$ and $b(0)=A\sin(\phi)=1.6$ which can't be.
Question 2: Is there a reason that (1) isn't legit?
Edit: Since I'm in a least square problem, I can't actually expect (1) to work, right? Anyway, Question 1 is the important question here.

The four residuals are $$b(t_k)-b_k$$ evaluated with the computed $\alpha,\beta$, which you can group as a sum of squares
$$\sum_{k=1}^4(b(t_k)-b_k)^2.$$
Also,
$$A=\sqrt{\alpha^2+\beta^2},\\\tan\phi=\frac\beta\alpha.$$
