I am just starting to learn Matlab, and I would be very grateful if someone could clarify my confusion...
I am trying to solve a non-uniform transport equation using the Lax-Wendroff scheme, with the code below. Matlab tells me that there are errors in the last line of the code (U(j+1,2:N)=(1/2).*sigma...), that is, 1. Error using *; 2. Inner matrix dimensions must agree.
I know the dimensions of sigma and U's are not compatible (as matrices), but I have no idea (and experience) on how to fix this... There's no problem with the formula, but I really find it hard to deal with the code.
a = -10;
b = 10;
delta_x = (b-a)/N;
x = a:delta_x:b;
tfinal = 2;
delta_t = tfinal/M;
t = 0:delta_t:tfinal;
c = 3-2.* exp(-(1/4).*(x.^2)) ;
sigma = c.*(delta_t/delta_x);
U=zeros(M+1,N+1);
U(1,:)=f(x);
for j=1:M
U(j+1,2:N)=(1/2).*sigma.*(sigma-1).*U(j,3:N+1)-((sigma).^2-1).*U(j,2:N)+(1/2).*sigma.*(sigma+1)*U(j,1:N-1);
end
Thank you so much!