Trigonometrical Least Squares (Linear Algebra)

674 Views Asked by At

Solutions which use matrices would be greatly appreciated.

Find the trigonometric function of the form $f(t) = c_0+c_1\sin(t)+c_2\cos(t)$ that best fits the data points $(0,0), (1,1), (2,2), (3,3)$ using least squares.

My question is, would I go about this in the same way as I would if I was using a least squares approach to fit 4 sets of coordinates to a quadratic line? Or does the trigonometry result in me having to go about this question in a different way? If so, how?

1

There are 1 best solutions below

0
On BEST ANSWER

You have a trial function and let's generalize the data to the sequence $\left\{ t_{k}, f_{k} \right\}_{k=1}^{m}$. The linear system takes the form $$ \begin{align} \mathbf{A} \alpha &= f \\[3pt] % \left[ \begin{array}{ccc} \mathbf{1} & s & c \end{array} \right] % \left[ \begin{array}{c} \alpha \end{array} \right] % &= \left[ \begin{array}{c} f \end{array} \right] % \\[5pt] % \left[ \begin{array}{ccc} 1 & \sin t_{1} & \cos t_{1} \\ 1 & \sin t_{2} & \cos t_{2} \\ \vdots & \vdots & \vdots \\ 1 & \sin t_{m} & \cos t_{m} \end{array} \right] % \left[ \begin{array}{c} \alpha_{0} \\ \alpha_{1} \\ \alpha_{2} \end{array} \right] % &= % \left[ \begin{array}{c} f_{1} \\ f_{2} \\ \vdots \\ f_{m} \end{array} \right]. \end{align} $$

Set up the normal equations: $$ \begin{align} \mathbf{A}^{*} \mathbf{A} \alpha &= \mathbf{A}^{*} f \\[3pt] % \left[ \begin{array}{ccc} \mathbf{1} \cdot \mathbf{1} & \mathbf{1} \cdot s & \mathbf{1} \cdot c \\ s \cdot \mathbf{1} & s \cdot s & s \cdot c \\ c \cdot \mathbf{1} & c \cdot s & c \cdot c \end{array} \right] % \left[ \begin{array}{c} \alpha_{0} \\ \alpha_{1} \\ \alpha_{2} \end{array} \right] % &= % \left[ \begin{array}{c} \mathbf{1} \cdot f \\ s \cdot f \\ c \cdot f \end{array} \right]. & \end{align} $$

Solve the normal equations: $$ \begin{align} \alpha &= \left( \mathbf{A}^{*} \mathbf{A} \right)^{-1} \mathbf{A}^{*} f \\[3pt] % \left[ \begin{array}{c} \alpha_{0} \\ \alpha_{1} \\ \alpha_{2} \end{array} \right] % &= % \left[ \begin{array}{ccc} \mathbf{1} \cdot \mathbf{1} & \mathbf{1} \cdot s & \mathbf{1} \cdot c \\ s \cdot \mathbf{1} & s \cdot s & s \cdot c \\ c \cdot \mathbf{1} & c \cdot s & c \cdot c \end{array} \right]^{-1} % \left[ \begin{array}{c} \mathbf{1} \cdot f \\ s \cdot f \\ c \cdot f \end{array} \right]. & \end{align} $$