# how to define unit vectors in mathematica

I'm struggling a little bit trying to understand how to address this problem, I would like to do this in mathematica: is just that I don't know how to do the dot product between $$\mathbf{J}$$ and $$\mathbf{a}_y$$ because I don't know how to define the unit vector $$\mathbf{a}_y$$, is it possible to do this in mathematica? thanks in advance!

• I don't understand what it's supposed to represent but maybe UnitVector[1] and UnitVector[2]? Or UnitVector[3, 1] etc. Commented May 10, 2021 at 4:43
• ax = {1, 0, 0}; ay = {0, 1, 0}; j = -10^4 Exp[-2 y] (Sin[2 x] ax + Cos[2 x] ay); Integrate[j.ay /. y -> 1, {z, 0, 2}, {x, 0, 1}] // N Commented May 10, 2021 at 5:50
• @LouisB Post it as an answer? Commented May 10, 2021 at 14:19
• Guys thank you for all your help,@LouisB solution was easy and simple, thanks a lot. Commented May 10, 2021 at 22:47

As shown by LouisB in the comment, use coordinate vector is the standard way to go, nevertheless, it's possible to implement the symbolic coordinate bases as follows:

Clear[Subscript]
Subscript /: Subscript[a, x_]^2 = 1;
Subscript /: Subscript[a, x_] Subscript[a, y_] /; x =!= y = 0;
Subscript[a_, b : x | y | z] := Subscript[a, ToString@b]

J = -10^4  (Subscript[a, x] Sin[2 x] E^(-2 y) + Subscript[a, y] Cos[2 x] E^(-2 y)) 10^3
Integrate[J Subscript[a, y] /. y -> 1, {z, 0, 2}, {x, 0, 1}] // N


Or more rigorously:

Clear[Subscript]
Subscript /: Subscript[a, x_].Subscript[a, x_] = 1;
Subscript /: Subscript[a, x_].Subscript[a, y_] = 0;
Subscript[a_, b : x | y | z] := Subscript[a, ToString@b]

J = -10^4 (Subscript[a, x] Sin[2 x] E^(-2 y) + Subscript[a, y] Cos[2 x] E^(-2 y)) 10^3
Integrate[J.Subscript[a, y] /. y -> 1 // TensorExpand, {z, 0, 2}, {x, 0, 1}] // N


• Thank you very much for your help @xzczd, in your code there are some things I still don't understand because I'm new using Mathematica but I will research and try to learn more, thank you for helping me out! Commented May 10, 2021 at 22:50