2
$\begingroup$

I know Mathematica can change the coordinate system with the command ''CoordinateTransform''.For example, you can change the coordinates of an $(x,y,z)$ vector in cartesian coordinates like this.

CoordinateTransform[
 "Cartesian" -> "Cylindrical", {x, y,z}]

And Mathematica will return the vector in the cylindrical coordinates system $(\rho,\phi,z)$.

However, I think it only works with some well-know basis such as the polar, the cylindrical the spherical... which the software has as default. I was wondering if this change of coordinates could be done for an arbitrary choice of the basis. For instance, say I want to plot several $\mathbb{R}^2$ vectors in this particular basis $\{(-1,-1),(1,1)\}$ for some reason. Can Mathematica do it?

$\endgroup$

2 Answers 2

2
$\begingroup$

This answer is similar to @DanielHuber's answer, but using the relevant linear algebra more explicitly:

basis = {{-1, 1}, {1, 1}};
vectors = {{1, 1}, {3, 2}, {0, 1}};
Inverse[basis] . # & /@ vectors
(* {{0, 1}, {-(1/2), 5/2}, {1/2, 1/2}} *)

If the vectors themselves are given in a non-standard basis, we first convert to the canonical basis:

basis0 = {{0, 1}, {1, 0}};
basis1 = {{-1, 1}, {1, 1}};
vectors = {{1, 1}, {3, 2}, {0, 1}};
Inverse[basis1] . basis0 . # & /@ vectors
(* {{0, 1}, {1/2, 5/2}, {-(1/2), 1/2}} *)

This makes use of the fact that converting a vector $\vec v$ from a given basis $(\vec b_i)_i$ to the canonical basis $(\hat{\vec e}_i)_i$ is simply given by the matrix-vector product,

$$\tilde{\vec v}=B\cdot\vec v$$

where $B$ is the matrix with the basis vectors $\vec b_i$ as rows (using Mathematica's convention of row/column vectors in relation to the dot product). Likewise, converting the other was is done by the inverse of the matrix,

$$\vec v=B^{-1}\cdot\tilde{\vec v}$$

$\endgroup$
1
  • $\begingroup$ Thank you both for the comments!! They've helped me a lot. Just one more thing: Do you know if it is possible to plot the vectors using the new basis (axis, gridline) just like PolarPlot does with the polar system?? $\endgroup$ Dec 1, 2022 at 14:28
1
$\begingroup$

To start with, {(−1,−1),(1,1)} is not a basis because the two vectors are antiparallel. I therefore take {(−1,1),(1,1)} as basis for an example.

Call the original bas bas0 and the new base, written in the old coordinates, bas1:

bas0 = {{1, 0}, {0, 1}};
bas1 = {{-1, 1}, {1, 1}};

We now need to write the old base vectors {1,0} and {0, 1} in the new base bas1.

{1, 0} == (-bas1[[1]] + bas1[[2]] )/2
{0, 1} == (bas1[[1]] + bas1[[2]] )/2

A vector: v=x{1,0}+y{0,1} in the old coordinates: {x,y} can be written in the new basis:v= xn{-1,1} + yn{1,1} with new coordinates:{xn,yn}. Therefore, to get the new from the old coordinates:

Solve[{x, y} . bas0 == {xn, yn} . bas1, {xn, yn}]

(* {{xn -> 1/2 (-x + y), yn -> (x + y)/2}} *)

We may define a function for this:

old2new[p:{x_,y_}]= {{-1,1}/2,{1,1}/2}.p

We may now test if a vector, written in the new coordinates, is still the same vector by:

old2new[{x, y}] . bas1 == {x, y} . bas0
(* True *)
$\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.