Function C+Dx closest f(x) = sin2x on the interval from −π to π by least squares

285 Views Asked by At

I am a little bit confused over the second part of the following problem:

  1. What is the closest function acos x +bsinx to the function f(x) = sin2x on the interval from −π to π? What is the closest straight line c+dx? (from Linear Algebra and Its Applications by Gilbert Strang p.210)

What I thought:

Given the function g(x) = C+Dx = $ \left( \begin{array}{cc} 1 & x \\ \end{array} \right) % \left( \begin{array}{cc} C \\ D \end{array} \right) $ I can solve the equation g(x)=f(x) $\Longleftrightarrow$ $ \left( \begin{array}{cc} 1 & x \\ \end{array} \right) % \left( \begin{array}{cc} C \\ D \end{array} \right) $ = $\sin(2x)$ by least squares: $$Ax=b$$ $$\Longleftrightarrow A^TA \hat x = A^Tb$$

$$\Longleftrightarrow \left( \begin{array}{cc} 1 \\ x \end{array} \right) % \left( \begin{array}{cc} 1 & x \\ \end{array} \right) % \left( \begin{array}{cc} \hat C \\ \hat D \end{array} \right) = \left( \begin{array}{cc} 1 \\ x \end{array} \right) \sin(2x)$$

$$\Longleftrightarrow \left( \begin{array}{cc} (1,1) & (1,x) \\ (x,1) & (x,x) \end{array} \right) % \left( \begin{array}{cc} \hat C \\ \hat D \end{array} \right) = \left( \begin{array}{cc} (1,\sin(2x) \\ (x, \sin(2x) \end{array} \right)$$

$$\Longleftrightarrow \left( \begin{array}{cc} \int_{-\pi}^{\pi} (1 \cdot 1)dx & \int_{-\pi}^{\pi} (1 \cdot x)dx \\ \int_{-\pi}^{\pi} (x \cdot 1)dx & \int_{-\pi}^{\pi} (x \cdot x)dx \end{array} \right) % \left( \begin{array}{cc} \hat C \\ \hat D \end{array} \right) = \left( \begin{array}{cc} \int_{-\pi}^{\pi} (1 \cdot \sin(2x))dx \\ \int_{-\pi}^{\pi} (x \cdot \sin(2x))dx \end{array} \right)$$

$$\Longleftrightarrow \left( \begin{array}{cc} 2\pi & 0 \\ 0 & \frac{2\pi^3}{3} \end{array} \right) % \left( \begin{array}{cc} \hat C \\ \hat D \end{array} \right) = \left( \begin{array}{cc} 0 \\ -\pi \end{array} \right)$$

$$\Longleftrightarrow % \left( \begin{array}{cc} \hat C \\ \hat D \end{array} \right) = \left( \begin{array}{cc} 0 \\ \frac{-3}{2\pi^2} \end{array} \right).$$

Hence: $g(x) = \frac{-3}{2\pi^2}x$. However the solution states that $\hat C,\hat D = 0$ so $g(x)=0+0x$. If I look at the function in geogebra, $\hat C,\hat D=0$ is worse than $\hat C=0$, $\hat D=\frac{-3}{2\pi^2}$ but there seem to be even (slighly) better lines. There must be some error in my calculations but I cannot find it. Could somebody help me at this problem?