Finding least square solution for $f(t)=at+b\cos\left(\frac{\pi t}{4}\right)+5$

119 Views Asked by At

I have three points $(t,f(t))$: $(-3,1)$, $(0,5+\sqrt{2})$ ,$(1,7)$ and want to solve for $a$ and $b$ in the following functions, such that the solution is the best approximation to the overdetermined system.

$$f(t)=at+b\cos\left(\frac{\pi t}{4}\right)+5$$

Now I want to set up the Matrix $A$ such that I can solve for that solution using the normal equation $A^{t}Ax=A^{t}b$.

But I'm having a little trouble setting the matrix up such that I get a system $Ax=b$. I can calculate the values $\cos\left(\frac{\pi t}{4}\right)$ but how do I get the $+5$ into the system:

$$A\begin{pmatrix}a\\b\end{pmatrix}=y$$

It's probably a very simple fix...

3

There are 3 best solutions below

6
On

Pick a set of $t$'s: $t_1 = -1, t_2 = 0, t_3=1$ and evaluate $\cos (\pi t_i/4) = c_i$, let $f_1 = 1, f_2 = 5\sqrt{2}, f_3=4$ and form the matrix equation $$ \begin{pmatrix} t_1 & c_1 \\ t_2 & c_2 \\ t_3 & c_3 \end{pmatrix} \begin{pmatrix} a \\ b \end{pmatrix} = \begin{pmatrix} f_1 - 5 \\ f_2 -5 \\ f_3 -5 \end{pmatrix} $$ and solve it the way you propose...

2
On

$$f(t)=at+b\cos\left(\frac{\pi t}{4}\right)+5$$ $$\text{With }\quad\begin{cases}y=f-5\\ x=\cos\left(\frac{\pi t}{4}\right) \end{cases}\quad\to\quad y=at+bx$$ An usual linear regression for least squares fit will solve the problem.

1
On

If you are fitting $f(\mathbf{x})=a_1f_1(\mathbf{x})+\cdots+a_pf_p(\mathbf{x})+C$ where $C$ is a fixed constant such as the $5$ in your case, then the design matrix is:

$A= \begin{bmatrix} f_1(\mathbf{x}_1) & f_2(\mathbf{x}_1) & \cdots & f_p(\mathbf{x}_1)\\ f_1(\mathbf{x}_2) & f_2(\mathbf{x}_2) & \cdots & f_p(\mathbf{x}_2)\\ \vdots & \vdots & \ddots & \vdots\\ f_1(\mathbf{x}_n) & f_2(\mathbf{x}_n) & \cdots & f_p(\mathbf{x}_n)\\ \end{bmatrix}$

In your problem, you have $\mathbf{x}=t$, $f_1(t)=t$, $f_2(t)=\cos\frac{\pi t}{4}$, and $n=3$. You should be able to take it from here.