Example: Least Squares for non-Polynomials

checklist
Mark Yourself Question
  1. Grab a piece of paper and try this problem yourself.
  2. When you're done, check the "I have answered this question" box below.
  3. View the solution and report whether you got it right or wrong.

Example: Least Squares for non-Polynomials

Find the function of form c1sin(x)+c2cos(x)c_1\sin(x)+c_2\cos(x) which best fits the data points (π,3),(0,4),(π/2,5)(-\pi,-3),(0,-4),(\pi/2,-5) in the least squares sense.

Solution:

M=[sin(π)cos(π)sin(0)cos(0)sin(π/2)cos(π/2)]=[010110],y=[345],MTM=[1002],MTy=[51]M=\left[\begin{array}{ll}\sin(-\pi)&\cos(-\pi)\\\sin(0)&\cos(0)\\\sin(\pi/2)&\cos(\pi/2)\end{array}\right]=\left[\begin{array}{rr}0&-1\\0&1\\1&0\end{array}\right],\vec y=\left[\begin{array}{r}-3\\-4\\-5\end{array}\right],M^TM=\left[\begin{array}{rr}1&0\\0&2\end{array}\right],M^T\vec y=\left[\begin{array}{r}-5\\-1\end{array}\right]

The normal equations row reduce as: [105021][105011/2]\left[\begin{array}{rr|r}1&0&-5\\0&2&-1\end{array}\right]\rightarrow \left[\begin{array}{rr|r}1&0&-5\\0&1&-1/2\end{array}\right] , so the desired approximating function is f(x)=5sin(x)(1/2)cos(x)f(x)=-5\sin(x)-(1/2)\cos(x) .

More Least Squares Approximation Questions: