# Why isn't my vector equation solving correctly [closed]

Completely new to Mathematica, started using it yesterday. Don't have the luxury of time to read through a whole long 300 pages manual.

I need to calculate a point on two lines such that the vector between these points its perpendicular to both lines.

Define my points

A = {2, 1, -1};
B = {24, -2, 3};
qa = {23, 21, 3};
qb = {-12, -14, 2};


Solve for t1, and t2, the parameters for which the constraints are satisfied

sol = Solve[{
Dot[(A*t1 + qa) - (B*t2 + qb), A] == 0,
Dot[(A*t1 + qa) - (B*t2 + qb), B] == 0
}, {t1, t2}];


Extracting solutions and obtaining the points to which they refer, from the parameters

res = {a, b} /. sol[[1]];
r1 = res[[1]]
r2 = res[[2]]
p1 = A*r1 + qa;
p2 = B*r2 + qb;


I my test is n, the normal vector

n = Cross[A, B]


I compute the difference vector from the two points

dp = p2 - p1


And check if the dot products are zero

Dot[n, B](* => 0*)


But for dp it is not.

Dot[dp, B] (*=> not zero, but  *)


What is going on?

• In general it is recommended not to use capitol letters for user defined symbols as they may collide with predefined Mathematica symbols. – Jack LaVigne Feb 15 '17 at 14:56

What you did wrong was to not look at the intermediate results you were getting. If you had that you would have seen

res = {a, b} /. sol[[1]]


{a, b}

which is, of course, useless.

What you really want is

{a, b} = {t1, t2} /. sol[[1]]


{-(28017/1685), 166/1685}

Then

p1 = A*a + qa;
p2 = B*b + qb;
{p1, p2}


{{-(17279/1685), 7368/1685, 33072/1685}, {-(16236/1685), -(23922/1685), 3868/1685}}

dp = p2 - p1


{1043/1685, -(6258/337), -(29204/1685)}

Dot[dp, B]


0