Calculate $m_1, m_2 $ for $y = m_1x_1 + m_2x_2$

37 Views Asked by At

Given these values:

$$x_1 = \left\{1, 3, 6, 8\right\}$$ $$x_2 = \left\{2, 8, 5, 10\right\}$$ $$y = \left\{8.6, 30.8, 34.1, 53.8\right\}$$

And this formula

$$y = m_1x_1 + m_2x_2$$

How do I determine $m_1$ and $m_2$?

(In this case I purposely chose that values $m_1=3.6$ and $m_2=2.5$. I know how to do this in Excel using Linest, but I need the formula itself.)

2

There are 2 best solutions below

0
On BEST ANSWER

Let ${y_{Est}}_i = m_1{x_1}_i + m_2{x_2}_i$ be the estimated $y$ value.

Then the error $e_i = {y_{Est}}_i - y_i = m_1{x_1}_i + m_2{x_2}_i - y_i$

The sum of the squared errors is $\sum e_i^2 = \sum (m_1{x_1}_i + m_2{x_2}_i - y_i)^2$

We want minimise this with respect to $m_1$ and $m_2$

$\frac {\partial \sum e_i^2}{\partial m_1} = 2\sum {x_1}_i(m_1{x_1}_i + m_2{x_2}_i - y_i)=0$

$m_1 \sum {{x_1}_i}^2 + m_2 \sum {x_1}_i{x_2}_i - \sum {x_1}_i y_i=0$

$\frac {\partial \sum e_i^2}{\partial m_2} = 2\sum {x_2}_i(m_1{x_1}_i + m_2{x_2}_i - y_i)=0$

$m_1 \sum {x_1}_i{x_2}_i + m_2 \sum {{x_2}_i}^2 - \sum {x_2}_i y_i=0$

This gives you a pair of simultaneous equations to solve to find $m_1$ and $m_2$.

0
On

i will do this matrix form first. write the equations as $$Am = \pmatrix{1&2\\3&8\\6&5\\8&10}\pmatrix{m_1\\m_2} = \pmatrix{8.6\\30.8\\34.1\\53.8} = y$$ you solve the matrix equation $A^TAm = A^Ty$ gives you a $2\times 2$ system $$ \pmatrix{110&136\\136&193}\pmatrix{m_1\\m_2} = \pmatrix{736\\972.1} $$ which can be solved to get $$m1 = 3.6, m_2 = 2.5. $$