Please am writing a matlab code to solve a system of hyperbolic pde using Lax Friedrich's scheme \begin{equation} V_j^{n+1}=\frac{1}{2}(I+B)V_{j-1}^n+\frac{1}{2}(I-B)V_{j+1}^n \end{equation} where $V$ is a $3\times 1$ column matrix, $I$ is a $3\times 3$ identity matrix and $B$ is a $3\times 3$ matrix. I have been able to define all the parameters and it does run but in the nested for loop am having difficulty writing the above equation in matlab, I always get the error subscripted assignment dimension mismatch and I don't know how to figure out this. In my nested for loop, this is how I wrote the above equation:
for n = 1:Nt
for j = 1:Nx
V(j,n+n) = 1/2*(eye(3)+B)*V(j,n) + 1/2*(eye(3)-B)*V(j+2,n);
end
end
To save memory, we don't save the data at each iteration in time, but only the data from the last iteration. Thus, we create a $3\times N_x$ matrix
Vn, and a temporary $3\times N_x$ matrixVtempto avoid overwriting data during one time step. As written in the time-stepping formula of the Lax-Friedrichs scheme, the computation of $V_j^{n+1}$ requires $V_{j-1}^{n}$ and $V_{j+1}^{n}$. Therefore, one must be careful that the subscripts don't exceed the matrix dimensions when reaching the edges of the numerical domain. Here is a minimum working example in Matlab syntax: