# How to solve $Ax+By+z=C$ for $x$, $y$ and $z$?

This is my first post in this forum! So let me know if anything is not clear. Given a series of 10 different Values for $A$, $B$ & $C$. How to Solve for minimum value of $x$, $y$, $z$ respectively. $$Ax + B y + z = C$$ where $A$, $B$, $C$ are constants in the range $[0,255]$. Please provide me with some ideas to solve this with some samples.

Edit:

Note: Find the minimum values of $x$, $y$, $z$. You will be given $10$ sets of values for $A$, $B$, $C$ like these $[20,39,39]$, $[138,149,215]$, $[185,139,95]$, $[41,130,87]$, $[242,171,158]$, $[29,119,13]$, $[201,84,59]$, $[99,78,246]$, $[141,40,99]$, $[111,253,175]$.

• Are we given $10$ triples $(A,B,C)$ of values, over which we have to minimize the values of $x,y,z$. Also tell when is $x_1,y_1,z_1) <(x_2,y_2,z_2)$, that is would you say $(x,y,z) = (1,2,3)< (2,1,3)$ or vice versa?
– user174708
Commented Feb 17, 2015 at 12:30

You have a matrix equation $$\left[\begin{array}{ccc}A1&B1&1\\A2&B2&1\\...\\A10&B10&1\end{array}\right]\left[\begin{array}{c}x\\y\\z\end{array}\right]=\left[\begin{array}{c}C1\\C2\\...\\C10\end{array}\right]$$
or $MX=C$. This can't usually be solved exactly.
A minimum-error solution is $$X=(M^TM)^{-1}M^TC$$
Here, $(M^TM)$ is a $3\times3$ matrix, and $M^TC$ is a $3\times1$ vector.
NOTE: This is the same as @PdotWang's solution

• I'm marking this as an answer because this is more programmer friendly! Thank you for your answer! Commented Feb 18, 2015 at 9:37

Your question, I guess, would be that if we are given 10 equations, $$A_i x + B_i y + z = C_i \;\;(i=1,2,\cdot\cdot\cdot,10)$$ How to find the best solution for $(x,y,z)$?

Since we have more equations than unknowns $(10>3)$, we need to use the least square method to get the best solution for $(x,y,z)$.

Let,$$A_ix + B_i y + z - C_i = \delta_i \;\;(i=1,2,\cdot\cdot\cdot,10)$$ And,we need to find $(x,y,z)$ so that the following function $f(x,y,z)$ be minimized. $$f(x,y,z)=\sum_{i=1}^{10} \delta_i^2$$ $$\left\{\begin{matrix} \frac{\partial f}{\partial x}=0 \\ \frac{\partial f}{\partial y}=0 \\ \frac{\partial f}{\partial z}=0 \\ \end{matrix}\right.$$ It gives the following system of 3 equations with 3 unknowns. $$\left\{\begin{matrix} \sum_{i=1}^{10} (A_ix + B_i y + z - C_i)A_i =0\\ \sum_{i=1}^{10} (A_ix + B_i y + z - C_i)B_i =0\\ \sum_{i=1}^{10} (A_ix + B_i y + z - C_i)\cdot 1=0 \\ \end{matrix}\right.$$ This will lead to the solution of $(x,y,z)$