I have two time- and space-dependent vector fields, one which is:
$\mathbf A(x,y,t) = -y \, t \, \hat{\mathbf x} + x \, t \, \hat{\mathbf y}, \tag 1$
and another $\mathbf B(x,y,t)$ which is $\mathbf A$ translated $3/2$ units in the positive $\hat{\mathbf x}$ direction and $3/2$ units in the positive $\hat{\mathbf y}$ direction, so:
$\mathbf B(x,y,t) = - \left( y - \dfrac{3}{2} \right) \, t \, \hat{\mathbf x} + \left( x - \dfrac{3}{2} \right) \, t \, \hat{\mathbf y}. \tag 2$
I want to plot $\mathbf B$ evaluated at $t = 1$ in Mathematica. I tried two different ways but only one worked. The first one is directly from the expression (2):
$\mathbf B(x,y,1) = - \left( y - \dfrac{3}{2} \right) \, \hat{\mathbf x} + \left( x - \dfrac{3}{2} \right) \, \hat{\mathbf y}. \tag 3$
The resulting plot correctly shows the translation in both axes:
StreamPlot[{3/2 - y, -(3/2) + x}, {x, -5, 5}, {y, -5, 5}]
The second way I plot $\mathbf B(x,y,1)$ is by first defining $\mathbf A$ and then translating it. However, the resulting plot only shows $\mathbf A$ translated in the $\hat{\mathbf x}$ direction, even though B[1]
gives the same expression as (3):
Clear[A, B];
A[t_] := {-y*t, x*t};
B[t_] := ReplaceAll[ReplaceAll[A[t], x -> x - 3/2], y -> y - 3/2];
B[1]
StreamPlot[B[1], {x, -5, 5}, {y, -5, 5}]
Note that if you use the function VectorPlot
instead of StreamPlot
, the error is still present in the second method.
Why the second method didn't work? I want to fix it because I'm also using Mathematica to automatically translate the field $\mathbf A$.
Given that B[1]
is the same expression as (3), I think the problem is related with user-defining B
.
B[1]
withEvaluate@B[1]
? $\endgroup$