# Y=mx+b Solving for m

by Whalstib
Tags: solving
 P: 119 Hi, I've run into an issue with attempting to determine "m". In a chemistry class we're to determine "m" with one of several tools available. Most are using spread sheets which is causing the confusion. The problem arises when it seems only Excel allows one to simply set y to zero. This is explicitly mentioned in the text but no other spread sheets I've used are able to reliably do this. Excel gives m=27040 (with y=0) Using Numbers and Open Office I get m=30270 Using my HP50G I get m=30270 Using ∑xy/x^2 I get m=27040 I was able to simply use ∑xy/x^2 as I only had 10 values but I could have had hundreds which would have made the operation much more complex to do by hand. I want to believe the HP50G as I can have it at hand easier than Excel. I would assume HP50G solves with the common parameters.... but the raw math and Excel are the pair which seem more likely. So...why would one solve for y=0 or not? If it's important why is this function not readily available on common tools? Thanks, Whalstib
 P: 3,015 The least squares method is most easily remembered as: $$y = m x + b$$ Take $[f] \equiv \frac{1}{N} \, \sum_{i = 1}^{N}{f_{i}}$. Obviously $[c] = c$ and $[f + g] = [f] + [g]$. Taking the average of the above equation, we get: $$[x] \, m + b = [y] \\$$ Multiplying the equation by x and then taking the average, we get: $$[x^{2}] \, m + [x] \, b = [x y]$$ This system has the solution: $$m = \frac{[x y] - [x] \, [y]}{[x^{2}] - [x]^{2}}$$ $$b = [y] - m \, [x]$$
P: 2,728
 Quote by Whalstib So...why would one solve for y=0 or not? If it's important why is this function not readily available on common tools?
No, best I can guess from that post is you're talking about b=0. Please try to make sense when you post a question.

P: 2,728

## Y=mx+b Solving for m

When b=0 then it's not actually y=mx+b is it. It's a different (easier) problem of just y=mx, right!

The mean square error is proportional to :

$$f(m) = \sum_{i=1}^{N} \left(mx_i - y \right)^2$$

So

$$\frac{df}{dm} = 2 \sum_{i=1}^{N} x_i ( mx_i - y_i )$$

The mean squared error is minimized when df/dm=0, giving :

$$m = \frac{\sum x_i y_i}{\sum x_i^2}$$
P: 119
That's it!

I forgot it's not about setting y to zero but the y intercept to zero which is b!

Since there are at least 2 ways to solve is there an easy way to convert from the y=mx+b to y=mx+0?

Any HP50G users out there that can show me how to take a simple set of data and get a y=mx+b with y intercept (b) = 0?

Thanks,

Whalstib

 Quote by uart When b=0 then it's not actually y=mx+b is it. It's a different (easier) problem of just y=mx, right! The mean square error is proportional to : $$f(m) = \sum_{i=1}^{N} \left( y_i - mx_i \right)$$ So $$\frac{df}{dm} = 2 \sum_{i=1}^{N} x_i (y_i - mx_i)$$ The mean squared error is minimized when df/dm=0, giving : $$m = \frac{\sum x_i y_i}{\sum x_i^2}$$
P: 3,015
 Quote by Whalstib That's it! I forgot it's not about setting y to zero but the y intercept to zero which is b! Since there are at least 2 ways to solve is there an easy way to convert from the y=mx+b to y=mx+0?
If you equate the two different formulas for m (with $b \neq 0$ and $b = 0$), you will find that:

$$\frac{[x y] - [x] [y]}{[x^{2}] - [x]^{2}} = \frac{[x y]}{[x^{2}]}$$

$$[x^{2}] \, [x y] - [x^{2}] [x] [y] = [x^{2}] [x y] - [x]^{2} [x y]$$

$$[x] ([x] [x y] - [x^{2}] [y]) = 0$$

Since $[x] \neq 0$, it must mean that:

$$[x] [x y] - [x^{2}] [y] = 0$$

This is equivalent to:

$$b = [y] - m [x] = [y] - [x] \, \frac{[x y] - [x] [y]}{[x^{2}] - [x]^{2}} = \frac{[x^{2}] [y] - [x]^{2} [y] - [x] [x y] + [x]^{2} [y]}{[x^{2}] - [x]^{2}} = \frac{[x^{2}] [y] - [x] [x y]}{[x^{2}] - [x]^{2}} = 0$$

since the numerator is zero. The bottom line is, if b really is zero, then your result will not change by including another fitting parameter (b) in your fitting model, because it wll really turn out to be zero and the two formulas for m ought to give the same result. If, on the other hand, it turns out the calculated value for b is not zero, then is certainly makes no sense to impose that restriction on the fitting model. The values for m that you get by the two formulas are different then, but the correct one is the one I gave, because it does not make the additional assumption of $b = 0$.
P: 119
 Quote by uart No, best I can guess from that post is you're talking about b=0. Please try to make sense when you post a question.
yea sorry..

I was discussing this amongst friends and eventually got away from y intercept to simply y which still make sense to us in context but not those of you joining me on line.

Shows me I just need to slow down..

Thanks for actually figuring it out!

W
1. You should be able to get both $\sum x_i y_i$ and $\sum x_i^2$ from the "Summary Stats" after doing a conventional linear regression.
2. Enter x and y as vectors and use dot products. $m = (\tilde{x} \cdot \tilde{y}) \div (\tilde{x} \cdot \tilde{x})$