I have physical equations of motion that describe the dependence of one vector field on the components of another vector field. Without getting too much into detail, my differential equations involve a double curl that mixes the vector components on one side of the equation. Furthermore, I would like to discretize the space on which these equations are defined. So far I was able to set up the discretized equations:
$$ \frac{d}{dt}\ \begin{pmatrix} \vdots\\ P_x(i)\\ P_y(i)\\ P_z(i)\\ \vdots \end{pmatrix} = \begin{pmatrix} \vdots\\ A_y(i)-A_y(i+1)\\ -A_x(i)+A_x(i+1)-a*A_z(i)\\ b*A_y(i)\\ \vdots \end{pmatrix}\tag{1} $$ where a and b are some arbitrary constants and $\vec{A}$ and $\vec{P}$ are the two vector fields whose relation I want to determine. The lattice coordinates in one dimension are written as i (e.g. $\frac{d}{dt} P_x(7) = A_y(7)-A_y(8)$).
Is there any way to automatically turn this into a matrix multiplication? I would want the result to look something like
$$ \frac{d}{dt}\ \begin{pmatrix} \vdots\\ P_x(i)\\ P_y(i)\\ P_z(i)\\ P_x(i+1)\\ P_y(i+1)\\ P_z(i+1)\\ \vdots \end{pmatrix} = \begin{pmatrix} \ddots & \ddots & \ddots & \ddots & \ddots & \ddots & \ddots & \ddots \\ \ddots & 0 & 1 & 0 & 0 & -1 & 0 & \ddots\\ \ddots & -1 & 0 & -a & 1 & 0 & 0 & \ddots\\ \ddots & 0 & b & 0 & 0 & 0 & 0 & \ddots\\ \ddots & \ddots & \ddots & \ddots & \ddots & \ddots & \ddots & \ddots\\ \ddots & \ddots & \ddots & \ddots & \ddots & \ddots & \ddots & \ddots\\ \ddots & \ddots & \ddots & \ddots & \ddots & \ddots & \ddots & \ddots\\ \ddots & \ddots & \ddots & \ddots & \ddots & \ddots & \ddots & \ddots\\ \end{pmatrix} \begin{pmatrix} \vdots\\ A_x(i)\\ A_y(i)\\ A_z(i)\\ A_x(i+1)\\ A_y(i+1)\\ A_z(i+1)\\ \vdots \end{pmatrix} \tag{2} $$
You can already see from this example that there is some regularity as P(i+1), P(i+2), etc. will have the same entries in the matrix as the ones for P(i), only that the entries within the matrix will be at different positions.
So the question is: If I gave you the vector on the right-hand side of equation (1), could you give me the matrix on the right-hand side of equation (2)?
SparseArray[{ {i_, j_} /; Mod[i, 3] == 1 && j == i + 1 :> 1, {i_, j_} /; Mod[i, 3] == 1 && j == i + 4 :> -1, {i_, j_} /; Mod[i, 3] == 2 && j == i + 1 :> 1, {i_, j_} /; Mod[i, 3] == 2 && j == i + 3 :> -a, {i_, j_} /; Mod[i, 3] == 2 && j == i + 4 :> -1, {i_, j_} /; Mod[i, 3] == 0 && j == i + 1 :> b, ...}, {n, n}]
? $\endgroup$RepeatedNull
. The code is about as complete as the post and is merely a hint. $\endgroup$