Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i have an equation

$$\sum_{i=0}^m [w^{(i)}[(c-a^{(i)})-\frac{d^{(i)}(c-a^{(i)})\cdot d^{(i)}}{dis^2}]]=0$$ Where:

$a,b$ are two end points in a 3D Line. $d$ is a vector and vector $d=b-a$. the magnitude of the vector $|d|=dis$. I have many lines and therefore, i have many $a,b$ points. thats why above equation represent $a,d$ as $a^{(i)},d^{(i)}$ . However, this $dis$ is single scalar value and others have $3$ value components. this $\cdot$ is the dot product of the vector $c-a$ and vector $d$. $w^{(i)}$ is the weight (of a line).

As i said earlier, I have many points which represent different lines and thus i am using $a^{(i)}$ and $d^{(i)}$ to represent a point on a line and direction vector of line. but I have a one point which is outside to the lines and represent as $c$. Assume $i$ is lasting from $0$ to $m$. If I say the coordinates of points $a^{(i)},b^{(i)}$ are as $(x_1,y_1,z_1)^{(i)},(x_2,y_2,z_2){(i)}$ respectively. and the coordinate of point $c$ as $(x_0,y_0,z_0)$. then How do I convert this equation in to matrix form $[A][X] = [B]$. where $X$ represent the componenets of $c$ as this $(x_0,y_0,z_0)$ are unknown that i need to solve.

Please convert this equation to matrix form!

share|cite|improve this question
Please use latex to make your question more friendly. – Shiyu Sep 6 '11 at 8:02
@anon: i have modified the post. may be now it is clear. c is a point in 3D. – niro Sep 6 '11 at 8:48
up vote 1 down vote accepted

Write $\hat{d}{}^i$ for $d^i/|d^i|$. Thus we can remove the factor of $dis^2$ from the original equation by replacing each $d^i$ with $\hat{d}{}^i$. Now let $\otimes$ denote the outer product. Furthermore note that the vector $\hat{d}{}^i(\hat{d}{}^i\cdot\vec{c})$ can actually be rewritten as the product $(\hat{d}{}^i\otimes\hat{d}{}^i)\vec{c}$, and similarly for the $a^i$s - I recommend checking this yourself for good exercise. Now we can define the matrix $P=\sum_{i=0}^mw^i(I-\hat{d}{}^i\otimes\hat{d}{}^i)$ and the vector $\vec{\alpha}=\sum_{i=0}^m\vec{a}{}^i$. Let $I$ be the identity matrix. Then the original equation can be abridged to just $P(\vec{c}-\vec{\alpha})=\vec{0}$. You write $\vec{x}=\vec{c}$ and desire the equation $A\vec{x}=\vec{b}$. You should be able to see what you want to do from there.

share|cite|improve this answer
sorry i couldnt get you. actually in my post i left weights, though it was in my equation, for the simplicity. but, i couldnt figure out my equation with the weights according to your way as i cant get it clearly. could you please elaborate how my equation simplify in the form of Ax=B. finally i want to solve values for (xo,yo,zo) which is in 'c' in my equation. So, i am looking for the equation as (AX=B) with all xs,ys & zs as I need this for my normal equation in least square solutions. Please help me. – niro Sep 6 '11 at 10:16
@g_niro: I've augmented the equation to involve the weights. – anon Sep 6 '11 at 10:52
thank you very much for the explanation u gave me. – niro Sep 10 '11 at 14:55

What anon is suggesting is pictorially this: $$ \sum_{i=1}^n w_i\left(\begin{bmatrix} | \\ (c-a_i)\\ | \end{bmatrix} - \begin{bmatrix} | \\ \bar{d}_i\\ | \end{bmatrix}\begin{bmatrix} - &d_i^T&- \end{bmatrix} \begin{bmatrix} | \\ (c-a_i)\\ | \end{bmatrix} \right)=0 $$ where $\bar{d}_i$ is the normalized $d_i$ (and dot product is commutative). Factoring out $c-a_i$ gives $$ \sum_{i=1}^n w_i \underbrace{\left( I - \begin{bmatrix} | \\ \bar{d}_i\\ | \end{bmatrix}\begin{bmatrix} - &d_i^T&- \end{bmatrix} \right)}_{P_i}\begin{bmatrix} | \\ (c-a_i)\\ | \end{bmatrix}=0 $$ You can take the $a_i$ terms to the other side. The remaining step is to find a way to include the sum into a matrix format: $$ \underbrace{\begin{bmatrix} w_1I &w_2I &\dots w_nI \end{bmatrix} \begin{bmatrix} P_1\\P_2\\ \vdots \\P_n \end{bmatrix}}_{A}\underbrace{\begin{bmatrix}|\\c\\|\end{bmatrix}}_{x} = \underbrace{\begin{bmatrix} w_1I &w_2I &\dots w_nI \end{bmatrix} \begin{bmatrix} P_1 & & \\ &P_2\\ &&\ddots \\&&&P_n \end{bmatrix} \begin{bmatrix} a_1\\a_2\\ \vdots \\a_n \end{bmatrix}}_{b} $$ which is the $Ax=b$ form we wanted. Computationally, the form above is simply, ...ehm..., ridiculous. I just wanted to show you the general structure.

share|cite|improve this answer
thanks for the response. what i am trying is to find the point which is closest to 3 lines. after summing all 3 square distances (from that point to the lines) & getting derivatives with respect to $c$, then the equation should be arranged as $Ax=B$. So, in my equation $c=(x0,y0,z0)$ is the unknown and need to solve. since i have 3 lines, i have 3 values for $w$. it is really hard for me to figure out this equation with x,y,z coordniates as the coordinates have 3 components. any help please. – niro Sep 7 '11 at 0:22
though, i have 3 lines, i guess the demension of my matrics i.e. $A$ as 3x3, $x$ as 3x1 and $B$ as 3x1. (not sure) so, please show me how my equation would be, when we substitute $x,y,z$ & $w$ values. – niro Sep 7 '11 at 0:24
yes but this is already in the form that you want. I tried to sketch the dimensions with the $|$ and $-$ symbols. In other words, $c$ is the vector that you want to obtain. Check the labels of the underbraces, it is exactly in the form you wish to get. – user13838 Sep 7 '11 at 0:25
Let's go slowly. What is your first difficulty when reading my answer? – user13838 Sep 7 '11 at 0:26
what is the demension of $P1$? then what would be $w1I$, and $[w 1 I w 2 I …w n I ]$. if i have 4 lines, then what would be the dimension of matrix $A$. do we have 12 equations? if, possible please figure out this with x,y,z. plz. – niro Sep 7 '11 at 0:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.