4
$\begingroup$

Well, we've learned how to detect whether two vectors are perpendicular to each other using dot product.

 a.b=0

if two vectors parallel, which command is relatively simple.

for 3d vector, we can use cross product.

for 2d vector, use what?

for example,

 a={1,3}, b={4,x};
  a//b

How to use a equation to solve $x$.

I tried it, but this is a little complex.

  Projection[a, b] - a == 0
$\endgroup$
3
  • 4
    $\begingroup$ Is this question related to the software Mathematica or is it a math question? If so, then you should ask this rather in math.stackexchange.com $\endgroup$ Commented Nov 29, 2016 at 12:08
  • 1
    $\begingroup$ I know how to solve it in math. I just don't know how to use Mathematica to realize it. $\endgroup$ Commented Nov 29, 2016 at 12:12
  • 2
    $\begingroup$ Why not? What have you tried? It's important to always show what you did and where you got stuck. $\endgroup$
    – Szabolcs
    Commented Nov 29, 2016 at 12:15

4 Answers 4

9
$\begingroup$

$a$ and $b$ are parallel if $a = \kappa b$. Try

MatrixRank[{a, b}] == 1

for an easy way to test this. This works only if neither of the vectors have norm 0. Symbolic vector components (parameters) are considered independent by MatrixRank, so this method considers vectors parallel only if they are parallel for any value of the parameters.


For a fully general symbolic solution use

Reduce[a = k b, k]

a = {x, y};
b = {x, z};
Reduce[a == k b, k]

(* (y == z && k == 1) || (x == 0 && z != 0 && k == y/z) || (z == 0 && y == 0 && x == 0) *)

a = {1, 3};
b = {4, x};
Reduce[a == k b, {k, x}]

(* k == 1/4 && x == 12 *)
$\endgroup$
5
  • $\begingroup$ for example, a={1,2}, b={3,x},a//b, I hope solve a equation to get value of $x$. how to do this? $\endgroup$ Commented Nov 29, 2016 at 12:15
  • 3
    $\begingroup$ @tiankonghewo Your comment shows that you didn't describe your problem precisely. This is why it's important to show what you have tried. It is not at all clear from your question that this is what you wanted. Write the mathematical definition of what "parallel" means ($a=\kappa b$) and put it in Reduce . $\endgroup$
    – Szabolcs
    Commented Nov 29, 2016 at 12:21
  • $\begingroup$ a = {1, 2};b = {4, x};Reduce[a == k *b && k \[Element] Integers, {x, k}] this do not work. $\endgroup$ Commented Nov 29, 2016 at 12:26
  • 1
    $\begingroup$ @tiankonghewo It seems to me that it works fine. The equations you wrote have no solution, and Reduce tells you this. The only solution is k==1/4, which is not an integer. $\endgroup$
    – Szabolcs
    Commented Nov 29, 2016 at 12:27
  • $\begingroup$ yes, you are right. $\endgroup$ Commented Nov 29, 2016 at 12:32
12
$\begingroup$

Based on the definition of the scalar product for $d$-dimensional vectos

\begin{equation} a \cdot b = |a| |b| \cos(\phi) \end{equation}

you can create a test based only on vector operations. The vectors are parallel, if and only if the angle between them is $\phi = 0$ or $\phi = \pi$. So, if the following quantity $q$

\begin{equation} q = \frac{|a \cdot b|}{|a| |b|} \end{equation}

equals to 1, then the vectors are parallel. Mathematica code

(*Dimension*)
d = 7;
(*Generate vectors*)
a = RandomReal[{-1, 1}, d];
b = RandomReal[]*a;
(*Test*)
If[Abs[a.b]/(Norm[a]*Norm[b]) == 1, Print["Parallel"], 
 Print["Not parallel"]]

Parallel

Based on $q$ you can solve your problem for $x$. But I think you can figure that out.

$\endgroup$
1
  • 3
    $\begingroup$ Reduce[(a.b)^2 == a.a b.b] is indeed better than my suggestion of Reduce[a==k b]. For a={x,y}; b={x,z} your way gives the very clean x == 0 || y == z. Probably this should be the accepted answer. $\endgroup$
    – Szabolcs
    Commented Nov 29, 2016 at 12:47
3
$\begingroup$

Try this:

rule = {x_, y_} -> {x, y, 0};
Cross[a /. rule, b /. rule]

if

  a = {1, 1};
    b = {0.1, 0.1};

Cross[a /. rule, b /. rule]
(*  {0., 0., 0.}  *)

or alternatively

Cross @@ Map[Replace[#, rule] &, {a, b}] 

Have fun!

$\endgroup$
0
$\begingroup$

May be it's simple:

Det@{a,b}==0
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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