I want to use NDSolve for a complicated equation that contains vectors. I am still new to Mathematica, and have really enjoyed what I have learned thus far. Concerning this question, I have already studied and tested a few examples here, and here, but am still unable to grasp some portion of the proper nomenclature solve my equation using vectors in Mathematica. As an example, this is the Bloch Equation:
$$\frac{\partial\mathbf{M}}{\partial t}=\gamma\left[\mathbf{M} \times \mathbf{B}\right] $$
Here, $\mathbf{M}$ and $\mathbf{B}$ are vectors in Cartesian coordinates, $\mathbf{B}=B_x\hat{i}+B_y\hat{j}+B_z\hat{k}$ and $\mathbf{M}=M_x\hat{i}+M_y\hat{j}+M_z\hat{k}$.
I worked out a simple example, without vectors, with $\mathbf{B}=\hat{k}$:
eqn = {mx'[t] == my[t], my'[t] == -mx[t], my[0] == 1, mx[0] == 0}
sol1 = NDSolve[eqn, {mx[t], my[t]}, {t, 0, 20}]
mxx[t_] = mx[t] /. sol1[[1]];
myy[t_] = my[t] /. sol1[[1]];
ParametricPlot[{mxx[t], myy[t]}, {t, 0, totaltime}]
And this works just fine, but I have Mathematica 9.0.1, so I should be able to do it with vectors without performing the cross product by hand and entering it in. So here I take a shot at it:
H[x_, y_, z_] := {x, y, z};
eqn = {m'[t] == Cross[m[t], H[0, 0, 1]], m[0] == {1, 0, 0}}
sol1 = NDSolve[eqn, {m[t]}, {t, 0, 10}]
mm[t] = m[t] /. sol1[[1]];
Length[mm[t]]
But for the life of me, can't figure out what to do next. I have tried to plot this in a bunch of ways, but nothing seems to give me anything. The Length of my vector is just one. I am uncertain if I am using vectors in NDSolve wrong, or something else?
mm
this way:mm[t_] = m[t] /. sol1[[1]]
and comparemm[t]
withmm[0]
. (AnInterpolatingFunction
evaluates only on a numeric input.) $\endgroup$